gpt4 book ai didi

visual-studio - 以新的 CSPROJ 格式引用 GAC 程序集?

转载 作者:行者123 更新时间:2023-12-04 03:41:42 25 4
gpt4 key购买 nike

我正在使用 Visual Studio 2019 预览版 2.1。我有一个 .NET Framework 4.6.1 类库 C# 项目,它在旧的 csproj 项目格式(ToolsVersion="15.0")中有一些 Azure 引用。这个旧的 csproj 目前构建和工作得很好。我正在尝试迁移到新的项目格式。一切都很顺利,除了我有一个不是来自 NuGet 的引用资料——它来自 GAC:Microsoft.WindowsAzure.ServiceRuntime。但是,我还没有弄清楚如何获取新的项目格式来查找程序集。例如这里是新的项目文件:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="2.3.2" />
<PackageReference Include="Microsoft.Azure.KeyVault.Core" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.KeyVault.WebKey" Version="2.0.7" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="3.19.1" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.8" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.7" />
<PackageReference Include="Microsoft.WindowsAzure.ConfigurationManager" Version="3.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
<PackageReference Include="WindowsAzure.Storage" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.WindowsAzure.ServiceRuntime, Version=2.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Caching" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
</Project>

事实上,Microsoft.WindowsAzure.ServiceRuntime 引用正是旧格式中的一行。在 VS 中加载它时,它会产生以下警告:

警告 MSB3245 无法解析此引用。无法找到程序集“Microsoft.WindowsAzure.ServiceRuntime,Version=2.7.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL”。检查以确保程序集存在于磁盘上。如果您的代码需要此引用,您可能会收到编译错误。 MyProject C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2114

我试图删除版本:

<Reference Include="Microsoft.WindowsAzure.ServiceRuntime" />

但这并没有帮助。如果我删除它并尝试从 VS 用户界面添加引用,我会看到“框架”(GAC)中有一堆 Microsoft.* 和 System.* 选项,但 Microsoft.WindowsAzure.ServiceRuntime 不是其中之一他们。只是为了确认我启动了 ILSpy 并选择了“从 GAC 打开...”,果然它与一堆没有出现在 VS 用户界面中的其他程序集一起存在。

我怎样才能让 VS 从 GAC 加载这个引用?

谢谢

最佳答案

于是我找到了 this thread on GitHub这表明 未发现添加到 GAC 的程序集是预期行为:

This behaviour is by-design. You can opt back in as shown here. This should not be considered a workaround, but rather a deliberate and supported opt-in where you accept the consequences of having potentially different (and even incorrect) build behaviour on different machines.



解决方案是执行以下操作:

<PropertyGroup>
<AssemblySearchPaths>$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
</PropertyGroup>

即使不使用 HintPath,我也可以确认这完全解决了我的问题。

但自然的下一个问题是——如果在 GAC 中解析添加的程序集在默认情况下不起作用,为什么 Microsoft 不将 NuGet 用于 Azure SDK? NuGet 中唯一的官方 Azure 引用是旧的。这是否意味着任何使用新 CSPROJ 格式的 Azure 项目都需要手动将 GAC 添加到 AssemblySearchPaths 中?

关于visual-studio - 以新的 CSPROJ 格式引用 GAC 程序集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54490415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com