Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PackageReadmeFile outside csproj (in props file) doesn't work #12872

Closed
michael-hawker opened this issue Sep 7, 2023 · 5 comments
Closed

PackageReadmeFile outside csproj (in props file) doesn't work #12872

michael-hawker opened this issue Sep 7, 2023 · 5 comments
Labels
Functionality:Pack Resolution:NeedMoreInfo This issue appears to not have enough info to take action Type:Bug WaitingForCustomer Applied when a NuGet triage person needs more info from the OP

Comments

@michael-hawker
Copy link

NuGet Product Used

MSBuild.exe

Product Version

MSBuild version 17.7.2+d6990bcfa for .NET Framework

Worked before?

No response

Impact

It's more difficult to complete my work

Repro Steps & Context

The docs and most examples seem to indicate you should do something like this directly in the csproj file:

    <PackageReadmeFile>ReadMe.md</PackageReadmeFile>
  </PropertyGroup>
  
  <ItemGroup>
    <None Include="ReadMe.md">
      <Pack>True</Pack>
      <PackagePath>\</PackagePath>
    </None>
  </ItemGroup>

However, we have a bunch of projects which all share a props file and similar structure, so we wanted to abstract this to just detect if there was a ReadMe.md file in the source's project directory next to our csproj file, so I did this:

     <PackageReadmeFile Condition="Exists('$(MSBuildProjectDirectory)\ReadMe.md')">ReadMe.md</PackageReadmeFile>
  </PropertyGroup>
  
    <ItemGroup>
      <None Include="$(MSBuildProjectDirectory)\ReadMe.md" Pack="true" PackagePath="\" Condition="Exists('$(MSBuildProjectDirectory)\ReadMe.md')"/>
    </ItemGroup>

Which should be equivalent if a ReadMe.md file exists in the same folder as the csproj file (which they did).

The former works, but the latter produces this error upon pack:

Error: C:\Users\runneradmin.nuget\packages\nuget.build.tasks.pack\6.7.0\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(221,5): error NU5039: The readme file 'ReadMe.md' does not exist in the package. [C:\a\Windows\Windows\components\Triggers\src\CommunityToolkit.WinUI.Triggers.csproj]

Verbose Logs

No response

@heng-liu
Copy link
Contributor

heng-liu commented Sep 8, 2023

Hi @michael-hawker , I tried the following but was unable to repro.
Could you try the same steps and let me know if it works for you? And could you provide the repro steps if the following is not the same with yours? Thanks!
1.Create a Classlibrary1 project
2.Add a non-empty ReadMe.md file in solution folder
3.Create a common.props file in solution folder, with the following contents:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0">
 <PropertyGroup>
     <PackageReadmeFile Condition="Exists('$(MSBuildProjectDirectory)\ReadMe.md')">ReadMe.md</PackageReadmeFile>
  </PropertyGroup>
  
    <ItemGroup>
      <None Include="$(MSBuildProjectDirectory)\ReadMe.md" Pack="true" PackagePath="\" Condition="Exists('$(MSBuildProjectDirectory)\ReadMe.md')"/>
    </ItemGroup>
</Project>

4.Add <Import Project="common.props"/> into Classlibrary1.csproj file, so it's:

<Project Sdk="Microsoft.NET.Sdk">
  <Import Project="common.props"/>
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>
  1. Run dotnet pack, the package contains the Readme.md file as expected.

@heng-liu heng-liu added Functionality:Pack WaitingForCustomer Applied when a NuGet triage person needs more info from the OP labels Sep 8, 2023
@heng-liu
Copy link
Contributor

heng-liu commented Sep 8, 2023

BTW, we're considering a feature to automatically include a readme file if it satisfied a certain path. Do you think that would be helpful?
You may share your thoughts in #12385, thanks!

@michael-hawker
Copy link
Author

Thanks for clarifying @heng-liu, I realized after that I forgot to specify directly about the import step in the repro steps.

Main differences in the repro you laid out from what we're doing is our imported props file is in a different directory (not a parent one, e.g. ..\..\tooling\common.props) and imported at the end of our project file (if location matters).

We're also using msbuild over dotnet in our process.

@ghost ghost added WaitingForClientTeam Customer replied, needs attention from client team. Do not apply this label manually. and removed WaitingForCustomer Applied when a NuGet triage person needs more info from the OP labels Sep 11, 2023
@heng-liu
Copy link
Contributor

Hi @michael-hawker , thanks for your reply! Using msbuild and dotnet to pack should be the same.
From the msbuild doc: Properties are evaluated in the order in which they appear in the project file.
You may generate a msbuild binlog to check if the properties are evaluated as expected. https://learn.microsoft.com/en-us/shows/visual-studio-toolbox/msbuild-structured-log-viewer

@ghost ghost added WaitingForCustomer Applied when a NuGet triage person needs more info from the OP and removed WaitingForClientTeam Customer replied, needs attention from client team. Do not apply this label manually. labels Sep 11, 2023
@ghost ghost added the Status:No recent activity No recent activity. label Sep 26, 2023
@ghost
Copy link

ghost commented Sep 26, 2023

This issue has been automatically marked as stale because we have not received a response in 14 days. It will be closed if no further activity occurs within another 14 days of this comment.

@ghost ghost closed this as completed Oct 11, 2023
@ghost ghost added Resolution:NeedMoreInfo This issue appears to not have enough info to take action and removed Status:No recent activity No recent activity. labels Oct 11, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality:Pack Resolution:NeedMoreInfo This issue appears to not have enough info to take action Type:Bug WaitingForCustomer Applied when a NuGet triage person needs more info from the OP
Projects
None yet
Development

No branches or pull requests

2 participants