简体   繁体   English

Visual Studio 不会在项目和 NuGet 引用之间切换而不重新启动

[英]Visual Studio is not switching beween project and NuGet references without restarting

I'd like to be able to switch between NuGet and project references.我希望能够在 NuGet 和项目引用之间切换。 In order to achieve this I created custom solution and project configuration that I named Debug.csproj .为了实现这一点,我创建了名为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.我遇到的问题是 Visual Studio 确实在这些配置之间切换而无需重新启动它。 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 ).我可以在下拉列表中选择任何配置,但没有任何反应 - Dependecies树保持不变(它已在Configuration Manager中正确配置)。

Is there a way to trigger the change without restarting Visual Studio?有没有办法在不重新启动 Visual Studio 的情况下触发更改? (not sure whether this is relevant but the only custom extension I use is ReSharper) (不确定这是否相关,但我使用的唯一自定义扩展是 ReSharper)

Is there a way to trigger the change without restarting Visual Studio?有没有办法在不重新启动 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:由于您拥有相同的Platform ,您可以将其从条件中移动,例如:

  <ItemGroup Condition="'$(Configuration)' == 'Debug'">
    <PackageReference Include="..." Version="..." />
  </ItemGroup>

  <ItemGroup Condition="'$(Configuration)'=='Debug.csproj'">
    <ProjectReference Include=".." /> 
  </ItemGroup>

Hope this helps.希望这可以帮助。

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.解决方案资源管理器中的 Dependencies 节点似乎不会重新评估这种情况是否发生变化。

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).这是我采用的方法,只需更改ShouldUsePackageReferencesInDebug属性的值并保存项目文件就足以导致重新评估 Dependencies 节点(我可以看到一个项目从包中消失,另一个项目出现在项目中 - 反之亦然)。

<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.请注意,我已对其进行了设置,以便我们使用Release构建配置的构建管道将始终使用 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.这里的条件基于构建配置不是问题,因为没有需要重新评估的解决方案资源管理器实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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