project-system: Embedding package files through the project properties UI doesn't work when the package files are in the same directory as the project file

Visual Studio Version

I am using Visual Studio 2022 preview 5, however I believe the bug repros for all VS 2022 previews.

Summary

Embedding package files (README, package icon, license) through the package properties UI is broken when the files are in the same directory as the project file.

Embedding package elements through the package properties UI works as expected when the files are outside the project file directory.

Steps to Reproduce

  1. Create a class library project in VS 2022.
  2. Add a README.md file to the same directory as the project file.
  3. Add the README.md file to the package through the project properties UI. This generates the following XML in the project file:

<PackageReadmeFile>README.md</PackageReadmeFile>

and

  <ItemGroup>
    <None Update="README.md">
      <Pack>True</Pack>
    </None>
  </ItemGroup>
  1. Attempt to pack the package
  2. Pack fails with the following error even though the file is there:

NU5046: The readme file 'README.md' does not exist in the package.

Video from @timheuer:

2021-09-24_14-59-59

Expected Behavior

The generated XML should be:

<PackageReadmeFile>README.md</PackageReadmeFile>

and

  <ItemGroup>
    <None Include="README.md">
      <Pack>True</Pack>
      <PackagePath></PackagePath>
    </None>
  </ItemGroup>

This is already the behavior when embedded files are outside the project file directory.

Actual Behavior

When the package files are in the project file directory, the generated XML changes from <None Include="README.md"> into <None Update="README.md"> and omits the <PackagePath> node. This causes pack to fail.

<PackageReadmeFile>README.md</PackageReadmeFile>

and

  <ItemGroup>
    <None Update="README.md">
      <Pack>True</Pack>
    </None>
  </ItemGroup>

Another example using icons in the following image comparing VS 16.11 and VS 17.0 preview 5

User Impact

Embedding package files when they are in the same directory as the project file is broken in VS 2022. This is a very common scenario, especially for README files since each package in a repo will likely have a package-specific README in it’s project file directory.

This is likely to lead to significant frustration for package authors using VS 2022.

Addition examples for different package file locations

README is in same directory as proj file

README is in solution root directory

README is outside repo solution root directory

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

A warning is unfortunately still a breaking change for many of our customers 😦

Bug probably here, https://github.com/NuGet/NuGet.Client/blob/966b1b21eec28834365a8604744dab682c8326ea/src/NuGet.Core/NuGet.Build.Tasks.Pack/PackTaskLogic.cs#L630-L634, but yeah, I’m not sure we can change it easily.

We can add a warning and fix it later? Might anger folks either way.

I think that’s the same? It ends up with a different target (\readme.md vs readme.md) but I’m pretty sure those are the same? I think it’s good enough, at least. 😃

I believe it’s referring to an empty value being different to the value not being defined. Given the way you implement default values in MSBuild is with Condition=" ‘$(MyVar)’ == ‘’ ", I think it’s a clear signal that in general empty and undefined are more or less the same thing.

Oh, I totally missed that part.

That makes sense @MiYanni, I thought you were referring to something different. I thought you were referring to \ as an issue. I should have read the whole thread carefully.

Btw, I don’t think the first example in Addition examples for different package file locations in the body seems incorrect. README is in same directory as proj file

PackagePath is about the output, where the input is coming from is irrelevant.

\ is better.