Reputation: 18694
I'd like to be able to switch between NuGet and project references. In order to achieve this I created custom solution and project configuration that I named Debug.csproj
. I then moved packages to the appropriate section and put project reference in the other one:
<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PackageReference Include="..." Version="..." />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Debug.csproj|AnyCPU'">
<ProjectReference Include=".." />
</ItemGroup>
The problem I'm experiencing is that Visual Studio does switch between these to configurations without restarting it. I can select any configuration in the drop-down and nothing happens - the Dependecies
tree remains the same (it's correctly configured in the Configuration Manager
).
Is there a way to trigger the change without restarting Visual Studio? (not sure whether this is relevant but the only custom extension I use is ReSharper)
Upvotes: 2
Views: 219
Reputation: 13596
The problem with the approach that you describe in the question is that the condition is based on the build configuration. The Dependencies node in Solution Explorer does not appear to reevaluate if this changes.
It does however, appear to do so if you change a property. This is the approach that I went with and just changing the value of the ShouldUsePackageReferencesInDebug
property and saving the project file was enough to result in the Dependencies node being reevaluated (I could see an item disappear from Packages and another appear in Projects - or vice versa).
<PropertyGroup>
<ShouldUsePackageReferencesInDebug>false</ShouldUsePackageReferencesInDebug>
</PropertyGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PackageReference Include="<Package Name>" Version="1.0.0" Condition="$(ShouldUsePackageReferencesInDebug)" />
<ProjectReference Include="<Project Path>" Condition="!$(ShouldUsePackageReferencesInDebug)" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Release' ">
<PackageReference Include="<Package Name>" Version="1.0.0" />
</ItemGroup>
Note that I have it set up so that our build pipeline which uses the Release
build configuration will always use a PackageReference. That the condition here is based on the build configuration is not an issue as there is no instance of Solution Explorer that needs to be reevaluated.
Upvotes: 1
Reputation: 76890
Is there a way to trigger the change without restarting Visual Studio?
You can unload your project and reload the project. When you change the display in the Solution Explorer, you can trigger the change via reload the project file.
Since you have the same Platform
, you can move it from the condition, like:
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<PackageReference Include="..." Version="..." />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug.csproj'">
<ProjectReference Include=".." />
</ItemGroup>
Hope this helps.
Upvotes: 1