Skip to content

--no-restore broken since 4.6.5, preventing RestoreLockedMode #646

Closed

Description

@philipborg

If <RestoreLockedMode>true</RestoreLockedMode> is used in csproj/Directory.Build.props then in 4.6.4 you needed to use --no-restore to prevent a restore so another explicit restore with --force-evaluate can be used afterwards. Since 4.6.5 a restore is performed even with the --no-restore, making it incompatible with the property as the restore fails.

Tested and confirmed issue in both 4.6.5 & 4.6.7. Issue not present in 4.6.4.

Activity

  1. doterik commented on Feb 26, 2025

    @doterik

    Not exactly the same error, but dotnet outdated -u -n -f no longer finds any new updates after version 4.6.4, at least not for me.

    I tried adding the -pre flag, but then I got an exception ('auto' should be the default). I also tried with --pre-release auto but encountered the same exception.

    Downgrading from 4.6.7 version by version, I finally managed to get it working for me with 4.6.4.

    In conclusion, something vital has changed after version 4.6.4.

  2. darthkurak commented on Feb 27, 2025

    @darthkurak

    Same here. The behavior of dotnet outdated changed on our CI agents. Starting from version 4.6.5 RestoreLockedMode = true is not respected - packages.lock.json is generated - which prevents our automation from publishing app.

  3. adamtrepka commented on Feb 27, 2025

    @adamtrepka

    From version 4.6.5, there is a parameter --runtime. If we do not set it, it causes MSBuild to get the /p:RuntimeIdentifiers= parameter, which overwrites our settings.

    The missing value of the --runtime parameter should not set an empty value for the /p:RuntimeIdentifiers parameter in MSBuild

  4. amis92 commented on Feb 27, 2025

    @amis92

    I'd like to add that RestoreLockedMode doesn't seem to be an actual root issue.

    The restore is and has always been called to gather the dependency graph:

    "msbuild",
    projectPath,
    "/p:NoWarn=NU1605",
    "/p:TreatWarningsAsErrors=false",
    "/t:Restore,GenerateRestoreGraphFile",
    $"/p:RestoreGraphOutputPath={dgOutput}",
    $"/p:RuntimeIdentifiers={runtime}"

    There's no path that doesn't invoke this method. The --no-restore option is only used for Update operations (-u|--upgrade):

    ? _centralPackageVersionManagementService.AddPackage(project.ProjectFilePath, package.Name, package.LatestVersion, NoRestore)
    : _dotNetPackageService.AddPackage(project.ProjectFilePath, package.Name, project.Framework.ToString(), package.LatestVersion, NoRestore, IgnoreFailedSources);

    I may be missing something, but from the above I'd say that the RestoreLockedMode is just a collateral here. As mentioned by adamtrepka above, the p:RuntimeIdentifiers is currently always added to the restore, with an empty value if none was provided. This will overwrite the RuntimeIdentifiers set e.g. in project files or Directory.Build.props (and similar) with an empty value.

    The most important fix would be just adding this parameter conditionally. Another idea I've just had is to pass p:RestoreLockedMode=true - this will mean that running dotnet-outdated (without -u) on projects with lock files won't change the lock file (the parameter doesn't have impact on projects without lock files) - which actually sounds expected.

  5. sowa705 commented on Feb 27, 2025

    @sowa705
    Contributor

    #658 This PR should fix this issue

  6. doterik commented on Feb 28, 2025

    @doterik

    @sowa705 & @slang25,

    Does this PR also fix that flags without a value, i.e. omitting default values, also work?

    As mentioned in my earlier comment.

    Otherwise, remove the default value from all flags.

  7. slang25 commented on Feb 28, 2025

    @slang25
    Member

    @doterik do you have a repro I can test this with?

  8. sowa705 commented on Mar 4, 2025

    @sowa705
    Contributor

    @slang25 Hi, would it be possible to release a new version now that the fix is merged? I can try to help if you need anything done before 4.6.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions