How can I get my NuGet package to include its app.config in the build output directory of a project that consumes the NuGet package? Currently it is only copying the NuGetConfigInclude.exe but I need it to also have the NuGetConfigInclude.exe.config file. Note the consuming application uses a PackageReference in the .csproj file. It does not use packages.config.
NuGetConfigInclude.nuspec:
<?xml version="1.0"?>
<package >
<metadata>
<id>NuGetConfigInclude</id>
<version>1.0.0.0</version>
<title>NuGetConfigInclude</title>
<authors>NuGetConfigInclude</authors>
<owners>NuGetConfigInclude</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>NuGetConfigInclude</description>
<releaseNotes>Test Summary</releaseNotes>
<copyright>Copyright 2020</copyright>
<tags>TEST</tags>
</metadata>
</package>
Consuming application project file:
<ItemGroup>
<PackageReference Include="NuGetConfigInclude">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>
UPDATE:
I have managed to get the nuspec to include the file in the package but on the consuming project it is trying to compile the config file:
<?xml version="1.0"?>
<package >
<metadata>
<id>NuGetConfigInclude</id>
<version>24.0.0.0</version>
<title>NuGetConfigInclude</title>
<authors>NuGetConfigInclude</authors>
<owners>NuGetConfigInclude</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>NuGetConfigInclude</description>
<releaseNotes>Test Summary</releaseNotes>
<copyright>Copyright 2020</copyright>
<contentFiles>
<files include="contentFiles\any\any\assets\**" buildAction="None" copyToOutput="true" flatten="false" />
</contentFiles>
<tags>TEST</tags>
</metadata>
<files>
<file src="bin\Debug\NuGetConfigInclude.exe.config" target="contentFiles\any\any\assets"/>
</files>
</package>
Example Errors when building consuming project:
Severity Code Description Project File Line Suppression State Error CS1022 Type or namespace definition, or end-of-file expected NuGetConsumer C:\Users\GuestAcct.nuget\packages\nugetconfiginclude\24.0.0\contentFiles\any\any\assets\NuGetConfigInclude.exe.config 1 Active
This solution worked:
<?xml version="1.0"?>
<package >
<metadata>
<id>NuGetConfigInclude</id>
<version>29.0.0.0</version>
<title>NuGetConfigInclude</title>
<authors>NuGetConfigInclude</authors>
<owners>NuGetConfigInclude</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>NuGetConfigInclude</description>
<releaseNotes>Test Summary</releaseNotes>
<copyright>Copyright 2020</copyright>
<contentFiles>
<files include="**/*.*" buildAction="None" copyToOutput="true" flatten="true" />
</contentFiles>
<tags>TEST</tags>
</metadata>
<files>
<file src="bin\Debug\NuGetConfigInclude.exe.config" target="contentFiles\any\any\"/>
</files>
</package>
Important to note that if your consuming project is using PackageReference then the files need to be copied to a folder named contentFiles.