question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<contentFiles>.buildAction from NuGet package is overriden with "Compile"

See original GitHub issue

Steps 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 ==========

visual studio (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:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
andrekoehlercommented, Sep 7, 2018

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:

    <contentFiles>
      <files include="any/any/hello.txt" buildAction="Content" copyToOutput="true" flatten="false" />
      <files include="any/any/world.txt" buildAction="None"    copyToOutput="true" flatten="false" />
    </contentFiles>
0reactions
livarcocccommented, Sep 7, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Contentfile in nuget gets compiled causing build errors
When installing the nuget in a regular wpf app, I get a couple build errors. It appears that Visual Studio is trying to...
Read more >
NuGet ContentFiles Demystified - The NuGet Blog
ContentFiles are placed in a NuGet package in the /contentFiles folder and their capabilities are defined in the /package/metadata/contentFiles ...
Read more >
NuGet ContentFiles Demystified - CodeGenHero
“ContentFiles in NuGet are static files that the NuGet client will make available through the project.lock.json file [emphasis added] to a ...
Read more >
Creating a NuGet package for a library with platform- ...
NET Framework application when using the contentFiles folder. I strongly believe it is an important scenario and thus it must be supported.
Read more >
Random NuGet packages in Azure Artifacts
I have a CI/CD Pipeline that builds a .NET Core Solution, containing multiple Class Library Projects, to build NuGet Packages.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found