简体   繁体   中英

Nuget Update Package breaks Reference conditional

Some private Nuget packages in my solution are referenced by their local dlls in Debug and referenced as a nuget package in Release.

This is my Web.csproj:

<Choose>
<When Condition="'$(Configuration)' == 'Release'">
  <Reference Include="CustomPackage, Version=1.0.0.0, Culture=neutral">
    <HintPath>..\packages\CustomPackage.1.0.0\lib\net461\CustomPackage.dll</HintPath>
    <Private>True</Private>
  </Reference>
</When>
<Otherwise>
  <Reference Include="CustomPackage, Version=1.0.0.0, Culture=neutral">
    <HintPath >..\..\CustomPackage\bin\$(Configuration)\CustomPackage.dll</HintPath>
    <Private>True</Private>
  </Reference>
</Otherwise>
</Choose>

After CustomPackage gets published and updated to 1.0.1 , I update that package in the Nuget Package Manager for my Solution.

Problem: Nuget will then completely remove the first reference and place the updated reference outside of the conditional during the update.

I found Nuget Reference Switcher which I thought would be my solution by that wants you to add all projects you reference locally into the Solution which doesn't not work with my team and we need to reference just the dll. A GitHub Issue was filed with others having the same problem.

Is there any other approach besides this conditional?

Can I apply a transform to my Web.csproj with a Web.Debug.csproj during build?

Thanks, Alex

When we upgrade a NuGet package for our project, it will execute the Uninstall and Reinstall process which will modify our .csproj file to add the references into our project.

And we could not change our .csproj file during build, because the build process need to build your project based on the settings in .csproj.

All above processes are default action for nuget and project in Visual Studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM