Description
@marqdouj commented on Mon Oct 21 2019
If I am reading this page correctly, using TargetsForTfmSpecificContentInPackage in the *.csproj file is how I can create a nuget package that will add the content files to a *.csproj when it references that package?
I has created a .NET Standard 2.0 library project and was able to get the content files included in the nuget package using TargetsForTfmSpecificContentInPackage.
I then added the package to a local feed. However, when I reference the nuget package in a new project I was expecting it to add "AddFilesWithNuGet.lng" to the root of the project and create a new folder in the project "CSCommon" and add the "TestClass.cs" file.
This did not happen. Are my assumptions correct and that this should work or what am I missing here?
//*.nuspec file
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
...
<dependencies>
<group targetFramework=".NETStandard2.0" />
</dependencies>
<contentFiles>
<files include="CSCommon/TestClass.cs" buildAction="C# compiler" />
<files include="AddFilesWithNuGet.lng" buildAction="None" />
</contentFiles>
</metadata>
</package>
//*.csproj file
<PropertyGroup>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);CustomContentTarget</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<Target Name="CustomContentTarget">
<ItemGroup>
<TfmSpecificPackageFile Include="ContentFiles/TestClass.cs">
<PackagePath>contentFiles/CSCommon</PackagePath>
<BuildAction>C# compiler</BuildAction>
</TfmSpecificPackageFile>
<TfmSpecificPackageFile Include="ContentFiles/AddFilesWithNuGet.lng">
<PackagePath>contentFiles</PackagePath>
<BuildAction>none</BuildAction>
<CopyToOutput>true</CopyToOutput> //This did nothing; I was hoping it would add this to the files reference.
</TfmSpecificPackageFile>
</ItemGroup>
</Target>
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 099102e8-c320-ef50-6821-57519684dc98
- Version Independent ID: 1523dac4-419d-613d-2497-4062f9efd358
- Content: NuGet pack and restore as MSBuild targets
- Content Source: docs/reference/msbuild-targets.md
- Product: nuget
- GitHub Login: @karann-msft
- Microsoft Alias: karann