$(NugetPackageRoot) macro changes to "..\packages\...." in *.sfproj file automatically in VS2019, constantly requiring undo changes before push to Git

Viewed 1461

I'm having trouble with a *.sfproj in Visual Studio, as the *.sfproj file constantly gets checked out and constantly showing as having changes in the source control (git). Only opening the *.sproj as part of the solution modifies the file, and I can only undo the changes to this particular file after I close the entire solution, to be able to get the latest version of the project. It is upsetting to keep doing this every single time, especially since it may accidentally get checked in to the source control. The lines that get modified are:

  • on the server:
<Import Project="$(NugetPackageRoot)Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.props" Condition="Exists('$(NugetPackageRoot)Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.props')" />
<Import Project="$(NugetPackageRoot)Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets" Condition="Exists('$(NugetPackageRoot)Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets')" />
<Target Name="ValidateMSBuildFiles" BeforeTargets="PrepareForBuild">
   <Error Condition="!Exists('$(NugetPackageRoot)Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.props')" Text="Unable to find the '$(NugetPackageRoot)Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.props' file. Please restore the 'Microsoft.VisualStudio.Azure.Fabric.MSBuild' Nuget package." />
   <Error Condition="!Exists('$(NugetPackageRoot)Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets')" Text="Unable to find the '$(NugetPackageRoot)Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets' file. Please restore the 'Microsoft.VisualStudio.Azure.Fabric.MSBuild' Nuget package." />
</Target>
  • local:
<Import Project="..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.props" Condition="Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.props')" />
<Import Project="..\package*\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets')" />
<Target Name="ValidateMSBuildFiles" BeforeTargets="PrepareForBuild">
    <Error Condition="!Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.props')" Text="Unable to find the '..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.props' file. Please restore the 'Microsoft.VisualStudio.Azure.Fabric.MSBuild' Nuget package." />
    <Error Condition="!Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets')" Text="Unable to find the '..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.9\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets' file. Please restore the 'Microsoft.VisualStudio.Azure.Fabric.MSBuild' Nuget package." />
</Target>

I have this property defined in the *.sfproj as well:

<PropertyGroup>
    <NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
</PropertyGroup>

Basically $(NugetPackageRoot) changes to ..\packages\ on VS solution load. Do you have any ideas as how to avoid this change from occuring, so that the project file is not seen as modified by the source control?

1 Answers

$(NugetPackageRoot) macro changes to “..\packages\…” in *.sfproj file automatically in VS2019, constantly requiring undo changes before push to Git Ask Question

Suggestion

Please try to create a file called Directory.Build.props.

in your project folder.

Then add these in it:

   <Project>
    <PropertyGroup>
    <NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
   </PropertyGroup>
   </Project>

Then it will change to use your new path.

Update 1

You can try this:

Create a new file called Nuget.Config under solution folder(where the xxx.sln exists)

Then add these in it:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="%USERPROFILE%\.nuget\packages" />
</config>

</configuration>

Then you should also push the nuget.config under your solution into Source Control and then test it again.

The new Nuget.Config file will set the the nuget pakage to use the new referenced path(and my function works for packages.config which is the format you used).

Related