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

Enable dotnet add package with CPM #13009

Closed
delanym opened this issue Nov 13, 2023 · 12 comments
Closed

Enable dotnet add package with CPM #13009

delanym opened this issue Nov 13, 2023 · 12 comments
Labels
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

@delanym
Copy link

delanym commented Nov 13, 2023

NuGet Product Used

dotnet.exe

Product Version

7.0.402

Worked before?

No response

Impact

It's more difficult to complete my work

Repro Steps & Context

If I use CPM to control package versions I'm unable to add a package with this command

dotnet add package Testcontainers.MsSql

error: Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: Microsoft.NET.Test.Sdk;NUnit;NUnit.Analyzers;NUnit3TestAdapter;coverlet.collector

I expect to still be able to add a package.

Verbose Logs

No response

@jeffkl
Copy link
Contributor

jeffkl commented Nov 13, 2023

@delanym I'm sorry you're experiencing this issue. I am not able to reproduce the problem:

Directory.Packages.props:

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
</Project>

Example.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>
</Project>
D:\Repros\Example>dotnet add package Testcontainers.MsSql
  Determining projects to restore...
  Writing C:\Users\jeffkl\AppData\Local\Temp\tmpB25F.tmp
...
info : Package 'Testcontainers.MsSql' is compatible with all the specified frameworks in project 'D:\Repros\Example\Example.csproj'.
info : PackageReference for package 'Testcontainers.MsSql' added to 'D:\Repros\Example\Directory.Packages.props' and PackageVersion added to central package management file 'D:\Repros\Example\Example.csproj'.
info : PackageReference for package 'Testcontainers.MsSql' version '3.6.0' added to file 'D:\Repros\Example\Directory.Packages.props'.
info : Generating MSBuild file D:\Repros\Example\obj\Example.csproj.nuget.g.targets.
info : Writing assets file to disk. Path: D:\Repros\Example\obj\project.assets.json
log  : Restored D:\Repros\Example\Example.csproj (in 2.96 sec).

Then after, this is what I see in Directory.Packages.props:

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="Testcontainers.MsSql" Version="3.6.0" />
  </ItemGroup>
</Project>

And this is Example.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Testcontainers.MsSql" />
  </ItemGroup>
</Project>

I'm using .NET SDK 7.0.403. Can you confirm that your Directory.Packages.props exists a folder directly above that project folder or the project folder itself and sets the ManagePackageVersionsCentrally property to true? If the problem persists, can you please attach a sample project ZIP that reproduces the issue so we can investigate further?

@jeffkl jeffkl added the WaitingForCustomer Applied when a NuGet triage person needs more info from the OP label Nov 13, 2023
@delanym
Copy link
Author

delanym commented Nov 13, 2023

Directory.Packages.props exists several folders above the project folder (together with the solution file). I don't know of any requirement for it to be above my project folders.

@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 Nov 13, 2023
@jeffkl
Copy link
Contributor

jeffkl commented Nov 13, 2023

With the following folder structure, dotnet add package works for me:

│   Directory.Packages.props
│   global.json
│
├───Example
│       Example.csproj
│
└───Folder1
    └───Folder2
        └───Folder3
                Example2.csproj

Are you able to ZIP up an example with it not working so we can investigate?

@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 Nov 13, 2023
@delanym
Copy link
Author

delanym commented Nov 14, 2023

The same command works on Windows but it fails to detect CPM on Linux.

@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 Nov 14, 2023
@zivkan
Copy link
Member

zivkan commented Nov 14, 2023

What version of the .NET SDK are you using on Linux?

If you're using the version that's available in RedHat or Ubuntu's own distribution, they use .NET's "source build", which for reasons I don't understand is limited to "1xx" SDK versions (7.0.1xx, 6.0.1xx). The fix in NuGet was added in NuGet 6.5, and according to the release notes for NuGet 6.5, it's part of the 7.0.200 SDK. Therefore, on Linux, unless you're using Microsoft's packages.microsoft.com, you're probably running an older version of the SDK that doesn't yet have CPM support.

@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 Nov 14, 2023
@delanym
Copy link
Author

delanym commented Nov 14, 2023

read above pls zivkan

@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 Nov 14, 2023
@zivkan
Copy link
Member

zivkan commented Nov 14, 2023

I just tested on Ubuntu 22.04 under WSL2, and it worked for me 🤷

@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 Nov 14, 2023
@JonDouglas
Copy link
Contributor

JonDouglas commented Nov 14, 2023

I think there is an issue with .NET test projects related here. I am not on a computer but there's an issue with this exact pattern somewhere in a dotnet repo or our repo by @richlander. Specifically test projects are not following CPM practices and therefore blocks people from using it.

Here's mine I think mentioned here: #12768 (comment)

@jeffkl
Copy link
Contributor

jeffkl commented Nov 14, 2023

@delanym I think @JonDouglas is right, does your project have versions defined in it already for these packages:

  • Microsoft.NET.Test.Sdk
  • NUnit;NUnit.Analyzers
  • NUnit3TestAdapter
  • coverlet.collector

You'll need to remove the Version="<something>" from each of those <PackageReference /> items and add a corresponding <PackageVersion /> item in Directory.Packages.props instead. Alternatively, you can remove all of those PackageReference items and add them back one by one with dotnet add package.

Unfortunately, the existing project templates don't know about CPM and they add versions, we're tracking the work to get project templates updated here: #12967

@delanym
Copy link
Author

delanym commented Nov 14, 2023

This is the change to one project

-    <PackageReference Include="Core.System.Configuration.Install"/>
-    <PackageReference Include="Microsoft.CSharp"/>
-    <PackageReference Include="Microsoft.OpenApi"/>
-    <PackageReference Include="Newtonsoft.Json"/>
-    <PackageReference Include="System.ComponentModel.Annotations"/>
-    <PackageReference Include="System.Configuration.ConfigurationManager"/>
-    <PackageReference Include="System.Data.DataSetExtensions"/>
-    <PackageReference Include="System.Data.SqlClient"/>
-    <PackageReference Include="System.Diagnostics.EventLog"/>
-    <PackageReference Include="System.Management"/>
-    <PackageReference Include="System.Runtime"/>
-    <PackageReference Include="System.ServiceProcess.ServiceController"/>
+    <PackageReference Include="Core.System.Configuration.Install" />
+    <PackageReference Include="Microsoft.CSharp" />
+    <PackageReference Include="Microsoft.OpenApi" />
+    <PackageReference Include="Newtonsoft.Json" />
+    <PackageReference Include="System.ComponentModel.Annotations" />
+    <PackageReference Include="System.Configuration.ConfigurationManager" />
+    <PackageReference Include="System.Data.DataSetExtensions" />
+    <PackageReference Include="System.Data.SqlClient" />
+    <PackageReference Include="System.Diagnostics.EventLog" />
+    <PackageReference Include="System.Management" />
+    <PackageReference Include="System.Runtime" />
+    <PackageReference Include="System.ServiceProcess.ServiceController" />
+    <PackageReference Include="Testcontainers.MsSql" Version="3.6.0" />

and another test project

-    <PackageReference Include="Microsoft.NET.Test.Sdk"/>
-    <PackageReference Include="Moq"/>
-    <PackageReference Include="MSTest.TestAdapter"/>
-    <PackageReference Include="MSTest.TestFramework"/>
-    <PackageReference Include="NLog"/>
-    <PackageReference Include="System.Data.SqlClient"/>
+    <PackageReference Include="Microsoft.NET.Test.Sdk" />
+    <PackageReference Include="Moq" />
+    <PackageReference Include="MSTest.TestAdapter" />
+    <PackageReference Include="MSTest.TestFramework" />
+    <PackageReference Include="NLog" />
+    <PackageReference Include="System.Data.SqlClient" />
+    <PackageReference Include="Testcontainers.MsSql" Version="3.6.0" />

@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 Nov 14, 2023
@jeffkl
Copy link
Contributor

jeffkl commented Nov 14, 2023

@delanym Are you able to create a repro I can use to investigate further? A github repository or attached ZIP will help us understand better what's going on.

@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 Nov 14, 2023
@ghost ghost added the Status:No recent activity No recent activity. label Dec 5, 2023
@ghost
Copy link

ghost commented Dec 5, 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 Dec 20, 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 Dec 20, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

4 participants