Skip to content

ContentFiles have confusing VS Solution Explorer experience #8779

Open
@karann-msft

Description

@karann-msft

@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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions