<contentFiles>.buildAction from NuGet package is overriden with "Compile"
See original GitHub issueSteps to reproduce
1. Create NuGet package from the following nuspec:
.nuspec:
<?xml version="1.0"?>
<package>
<metadata minClientVersion="4.0">
<id>IssueExample</id>
<version>1.5.0</version>
<description>test</description>
<authors>Contoso Ltd.</authors>
<contentFiles>
<files include="contentFiles/any/any/hello.txt" buildAction="Content" copyToOutput="true" flatten="false" />
<files include="contentFiles/any/any/world.txt" buildAction="None" copyToOutput="true" flatten="false" />
</contentFiles>
</metadata>
<files>
<file src="hello.txt" target="contentFiles/any/any" />
<file src="world.txt" target="contentFiles/any/any" />
</files>
</package>
(You have to create the two text files hello.txt and world.txt in the folder where the nuspec is placed)
Download resulting NuGet package here: IssueExample.1.5.0.zip
Then upload it to a local NuGet source (with ‘nuget add IssueExample.1.5.0.nupkg -source C:\XYZ’ and configure that source in the Visual Studio settings.
2. Create new C# console project
‘dotnet new console’
3. Add reference to NuGet package:
project.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IssueExample" Version="1.5.0" />
</ItemGroup>
</Project>
Expected behavior
hello.txt is added to the project with build action “Content” with copyToOutput enabled world.txt is added to the project with build action “None” with copyToOutput enabled
Actual behavior
hello.txt is added to the project with build action “Compile” and with copyToOutput disabled world.txt is added to the project with build action “Compile” and with copyToOutput disabled
The C#-Compiler reports errors because it can not compile the txt files (Of course, because they do not contain any C# code but random text)
Visual Studio build output:
1>------ Rebuild All started: Project: project, Configuration: Debug Any CPU ------
1>C:\Users\Andre\.nuget\packages\issueexample\1.5.0\contentFiles\any\any\hello.txt(1,1,1,3): error CS1022: Type or namespace definition, or end-of-file expected
1>C:\Users\Andre\.nuget\packages\issueexample\1.5.0\contentFiles\any\any\world.txt(1,1,1,3): error CS1022: Type or namespace definition, or end-of-file expected
1>Done building project "project.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
(I did not change ‘Build Action’ manually)
‘dotnet build’ output:
Microsoft (R) Build Engine version 15.8.166+gd4e8d81a88 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restoring packages for C:\dev\IssueExample\project\project.csproj...
Installing IssueExample 1.5.0.
Generating MSBuild file C:\dev\IssueExample\project\obj\project.csproj.nuget.g.props.
Restore completed in 274,71 ms for C:\dev\IssueExample\project\project.csproj.
C:\Users\Andre\.nuget\packages\issueexample\1.5.0\contentFiles\any\any\hello.txt(1,1): error CS1022: Type or namespace definition, or end-of-file expected [C:\dev\IssueExample\project\project.csproj]
C:\Users\Andre\.nuget\packages\issueexample\1.5.0\contentFiles\any\any\world.txt(1,1): error CS1022: Type or namespace definition, or end-of-file expected [C:\dev\IssueExample\project\project.csproj]
Build FAILED.
C:\Users\Andre\.nuget\packages\issueexample\1.5.0\contentFiles\any\any\hello.txt(1,1): error CS1022: Type or namespace definition, or end-of-file expected [C:\dev\IssueExample\project\project.csproj]
C:\Users\Andre\.nuget\packages\issueexample\1.5.0\contentFiles\any\any\world.txt(1,1): error CS1022: Type or namespace definition, or end-of-file expected [C:\dev\IssueExample\project\project.csproj]
0 Warning(s)
2 Error(s)
Time Elapsed 00:00:02.08
Environment data
dotnet --info
output:
.NET Core SDK (reflecting any global.json):
Version: 2.1.401
Commit: 91b1c13032
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.401\
Host (useful for support):
Version: 2.1.3-servicing-26724-03
Commit: 124038c13e
.NET Core SDKs installed:
1.1.8 [C:\Program Files\dotnet\sdk]
1.1.9 [C:\Program Files\dotnet\sdk]
1.1.10 [C:\Program Files\dotnet\sdk]
2.1.4 [C:\Program Files\dotnet\sdk]
2.1.100 [C:\Program Files\dotnet\sdk]
2.1.101 [C:\Program Files\dotnet\sdk]
2.1.102 [C:\Program Files\dotnet\sdk]
2.1.103 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
2.1.200 [C:\Program Files\dotnet\sdk]
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.300 [C:\Program Files\dotnet\sdk]
2.1.400 [C:\Program Files\dotnet\sdk]
2.1.401 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.3-servicing-26724-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
I solved it. The path in the <files> element must be relative to the contentFiles folder even though the documentation at https://docs.microsoft.com/en-us/nuget/reference/nuspec#using-the-contentfiles-element-for-content-files says “The path is relative to the .nuspec file”
correct:
Closing this issue then as the SDK is behaving as expected and you already filled an issue for the documentation. Thanks for reporting and getting to the bottom of it.