Paket
Paket copied to clipboard
Cannot configure content handling (build action) with sdk projects
Description
I need to create a nupkg with Paket, and am using a paket.template file for this. The source project is using Paket. I need to build some content files (actually, several .exe and .dll files) into the package, and when the package is being installed in an SDK-style project, the files need to be copied to output directory. Currently, however, they are added as compile, without any way to modify this.
Repro steps
- Create a paket.template file with the following contents:
type file
id MyPackage
version $VERSION$
files
Some.exe ==> contentFiles/any/any/Some
(not sure if additional attributes are needed, but this is a minimalistic example)
- Build the package with Paket.
- Install the package into an SDK-style project using vanilla NuGet.
Expected behavior
The executables are added to the project as content. This will work fine when manually creating a NuSpec file as follows:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>MyPackage</id>
... snip ...
<contentFiles>
<files include="any\any\Some\*" buildAction="Content" copyToOutput="true" />
</contentFiles>
</metadata>
<files>
<file src="Some.exe" target="contentFiles\any\any\Some"/>
</files>
</package>
Note: When building the package with NuGet, the files element is removed, but the metadata/contentFiles element stays there.
Actual behavior
The executables are added to the project as compile, resulting in a compiler error.
Known workarounds
It seems there is no way to add the metadata/contentFiles attribute by modifying the paket.template file, or at least there is nothing in the documentation. There seems to be no way to change the target behaviour. The only way I found is to use NuGet.exe rather than Paket to generate the package, which would be annoying, since the source project is Paket-only, or to modify the .nuspec file in the generated package, which would also be annoying.
I found several issues related to this, but none of them seem to actually provide any means to modify the build action of content files, one of them was #3269. But my problem is not about installing or not installing content files, and not about automatically determining the build action: It is about how to specify the build action in the paket.template file or, more precisely, how to create the mentioned contentFiles element in the resulting .nuspec.
There still does not seem to be a mechanism for this. Another workaround if you want to use paket is to add a .targets files that include the content files in the project where the package is installed.
The package.template for this would look like:
type file
id MyLib
authors Me
description
MyLib
files
AdditionalFiles\**\* ==> SomeFolder
MyLib.targets ==> build
And here is an example of how my MyLib.targets file looks:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\SomeFolder\myFile.foo" Visible="false">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
.....
</ItemGroup>
</Project>
Note: "Visible=false" hides the files from the solution explorer in the installed projects. I also intentionally gave the folder containing my additional files a custom name "SomeFolder" to make sure that in case there are special rules for "contentFiles" nothing unintended happens.