Nuget package to copy exe content file to project output directory

  • Thread starter Thread starter Dudeman 3000
  • Start date Start date
D

Dudeman 3000

Guest
I'm attempting to create a Nuget package that will copy an executable file to the output directory of a .Net framework web project.

Here is my nuspec file:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>CopyExeToOutputNugetPackage</id>
<version>1.0.0</version>
<authors>Some Dude</authors>
<owners>Some Owner</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A package to copy an exe to the output directory.</description>
<tags>CopyExeToOuput</tags>
<contentFiles>
<files include=".\content\test.exe" buildAction="None" copyToOutput="true" />
</contentFiles>
</metadata>
</package>

The "nuget pack" command works fine and builds my .nupkg file. I can then add the nuget project to my .Net Framework project and the test.exe file is added to my project, this is the entry in the .csproj file:

<ItemGroup>
<Content Include="test.exe" />
</ItemGroup>
I can then use Visual Studio to edit the file properties to copy to the output directory and my project file is updated:


<ItemGroup>
<Content Include="test.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>


I would prefer that this last manual step is not required.

I've attempted to use a .targets file but that's either the wrong thing to do (because there is no compilation and msbuild is not involved) or I never got the configuration correct.

I've also tried using the nuspec files element:

<files>
<file src="test.exe" target="lib\net462" />
</files>


With this last files element configuration, I get the following exception when attempting to add the nuget package to my .Net Framework v4.6.2 project:

Failed to add reference to 'test'. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

Is there a way for me to specify in the .nuspec file that the contentFiles should be copied to the output directory? It seems like the copyToOutput="true" attribute should do the job but that does not appear to be the case.




Continue reading...
 
Back
Top