I have a .NET Standard 2.0 project that is being packed into a NuGet package upon build. (Using the .csproj approach to generate a package on build) This project contains a file ApiClientSettings.json
, which I want to copy to the output directory of the consuming project.
I have the following in my .csproj:
<ItemGroup><Content Include="ApiClientSettings.json"><CopyToOutputDirectory>Always</CopyToOutputDirectory><PackageCopyToOutput>true</PackageCopyToOutput><PackagePath>contentFiles\any\any\;content</PackagePath></Content></ItemGroup>
According to MS documentation, the PackageCopyToOutput
attribute should do exactly what I want to do, but it does not seem to work when I install the package into a .NET Framework project. (Works perfectly for .NET Core project)
Am I missing anything else?
Here is my entire .csproj file:
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>netstandard2.0</TargetFramework><GeneratePackageOnBuild>true</GeneratePackageOnBuild><IsPackable>true</IsPackable><TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput><AllowedOutputExtensionsInPackageBuildOutputFolder> $(AllowedOutputExtensionsInPackageBuildOutputFolder);.json</AllowedOutputExtensionsInPackageBuildOutputFolder><Version>1.0.40</Version><AssemblyVersion>1.0.2.0</AssemblyVersion><FileVersion>1.0.2.0</FileVersion><IncludeContentInPack>true</IncludeContentInPack></PropertyGroup><PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"><OutputPath></OutputPath></PropertyGroup><ItemGroup><Content Include="ApiClientSettings.json"><CopyToOutputDirectory>Always</CopyToOutputDirectory><PackageCopyToOutput>true</PackageCopyToOutput><PackagePath>contentFiles\any\any\;content</PackagePath></Content></ItemGroup><ItemGroup><PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" /><PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.5" /><PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.5" /><PackageReference Include="Microsoft.Extensions.Http" Version="3.1.5" /><PackageReference Include="Newtonsoft.Json" Version="12.0.3" /></ItemGroup><ItemGroup><ProjectReference Include="..\DbModelLibrary\DbModelLibrary.csproj"><ReferenceOutputAssembly>true</ReferenceOutputAssembly><IncludeAssets>DbModelLibrary.dll</IncludeAssets></ProjectReference></ItemGroup><Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage"><ItemGroup><BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" /></ItemGroup></Target></Project>
Here is my generated .nuspec file aswell:
<?xml version="1.0" encoding="utf-8"?><package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"><metadata><id>Iso17025ApiClient</id><version>1.0.40/version><requireLicenseAcceptance>false</requireLicenseAcceptance><description>Package Description</description><dependencies><group targetFramework=".NETStandard2.0"><dependency id="Microsoft.AspNet.WebApi.Client" version="5.2.7" exclude="Build,Analyzers" /><dependency id="Microsoft.Extensions.Configuration" version="3.1.5" exclude="Build,Analyzers" /><dependency id="Microsoft.Extensions.Configuration.Json" version="3.1.5" exclude="Build,Analyzers" /><dependency id="Microsoft.Extensions.Http" version="3.1.5" exclude="Build,Analyzers" /><dependency id="Newtonsoft.Json" version="12.0.3" exclude="Build,Analyzers" /></group></dependencies><contentFiles><files include="any/netstandard2.0/ApiClientSettings.json" buildAction="Content" copyToOutput="Always" /></contentFiles></metadata></package>