Coder Social home page Coder Social logo

Comments (6)

brettfo avatar brettfo commented on August 24, 2024 1

@nkolev92 I was able to repro this. I created a repo at https://github.com/brettfo/13453 with all of the relevant information in the README, but the short version is that a Directory.Build.props further up the tree sets the ManagePackageVersionsCentrally property to false and in the /src directory, Directory.Packages.props used to be able to override this property in the 205 SDK, but it doesn't in the 300 SDK. It's a regression between the versions, but it's certainly possible that it only "worked" in 205 on accident.

from home.

AR-May avatar AR-May commented on August 24, 2024

Issue moved from dotnet/msbuild#10157


From @AR-May on Tuesday, May 21, 2024 2:05:08 PM

Team triage: it seems like it is a NuGet issue, moving it to NuGet repository.

from home.

nkolev92 avatar nkolev92 commented on August 24, 2024

@AR-May

There's some breaking changes for CPM opt-in in 8.0.3xx, namely: https://learn.microsoft.com/en-us/nuget/release-notes/nuget-6.10#breaking-changes.

In particular, you shouldn't need ManagePackageVersionsCentrally anymore.

Now, I'm not sure I see how that breaking change could lead to the behavior you're seeing.

I'm not able to repro it with: https://github.com/nkolev92/13453

E:\NuGet\temp\13453 [main ≡]> dotnet restore
  Determining projects to restore...
  Restored E:\NuGet\temp\13453\13453.csproj (in 212 ms).
E:\NuGet\temp\13453 [main ≡]> dotnet --version
8.0.300
E:\NuGet\temp\13453 [main ≡]>

Can you help me understand how my repro is different from yours?

from home.

nkolev92 avatar nkolev92 commented on August 24, 2024

I think only Directory.Packages.props is supposed to be imported.
Very likely that it was accidentally working.

cc @jeffkl

from home.

tomasfabian avatar tomasfabian commented on August 24, 2024

In my case, I disabled ManagePackageVersionsCentrally in the root Directory.Build.Props file for the entire solution. This detail wasn't included in my original issue that was transferred here:

<Project>
    <PropertyGroup>
        <ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
    </PropertyGroup>
</Project>

and enabled it only for individual test projects:

<Project Sdk="MSTest.Sdk/3.3.1">

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <IsPackable>false</IsPackable>
    </PropertyGroup>

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

    <ItemGroup>
        <PackageReference Include="FluentAssertions" />
    </ItemGroup>

</Project>

If it is no longer possible to configure ManagePackageVersionsCentrally in the Directory.Build.Props file in the root folder, I can move the Directory.Packages.Props file to the UnitTests subfolder.

from home.

jeffkl avatar jeffkl commented on August 24, 2024

It seems that this has to do with MSBuild import order. Any Directory.Build.props next to the project or any parent folder is imported first. A little after that, the Directory.Packages.props is imported but only if ManagePackageVersionsCentrally is set to true. Since you're disabling central package management (CPM) in Directory.Build.props, its too late to enable it in a project since the Directory.Packages.props was already not imported.

Its rather usual to use central package management but only for a select set of projects. Like you suggested, you could move Directory.Packages.props to a sub-directory with only those projects in it. Alternatively, you can create a Directory.Build.props next to each project that wants to use CPM with ManagePackageVersionsCentrally=true:

Project-level Directory.Build.props:

<Project>
  <PropertyGroup>
        <!-- Enable CPM for the project in this directory -->
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>

  <!-- Import parent Directory.Build.props which respects the ManagePackageVersionsCentrally property already being set  -->
  <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
</Project>

Root Directory.Build.props:

<Project>
  <PropertyGroup>
    <!-- Disable CPM by default unless something already enabled it -->
    <ManagePackageVersionsCentrally Condition="'$(ManagePackageVersionsCentrally)' != 'true'">false</ManagePackageVersionsCentrally>
  </PropertyGroup>
</Project>

I'm closing this issue as "by design" for now since with Directory.Build.props its not possible to disable CPM globally but then enable it per-project.

from home.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.