gpt4 book ai didi

visual-studio-2017 - Nuget 无法恢复 Microsoft.Net.Compilers.1.0.0

转载 作者:行者123 更新时间:2023-12-04 00:53:59 28 4
gpt4 key购买 nike

我正在尝试安装/恢复 Microsoft.Net.Compilers.1.0.0在 VS 2017 中使用 Nuget 包管理器。在输出中,它显示恢复已完成。但是当我查看 packages 时文件夹我看不到 Microsoft.Net.Compilers文件夹。
因为我得到错误

Severity Code Description Project File Line Suppression State Error This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ....\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props. XXXXX\Src\Api\Api.csproj 296



在 csproj 文件中,顶部有一行
<Import Project="..\..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />

背景
此问题发生在目标框架为 4.6.2 的 Web API 项目中。
我也有 NET Standard 1.4我想与不同类型的 .NET 应用程序共享的库。当我添加 NET Standard Library 的引用时到 Web API 项目,我得到了 missing dependencies issues .因此,根据建议,我编辑了 .csproj 文件并添加了
  <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

这修复了缺少的依赖项问题。

然后我删除了 package.config文件,从 packages 中删除了所有包文件夹并添加回所有包(除了我无法添加 Microsoft.Net.Compilers)。包引用现在位于 .csproj 文件中

那里 SO在这里发帖,但就我而言 Microsoft.Net.Compilers甚至没有恢复到 packages文件夹。 VS 2017 显示恢复完成,但我不知道它实际处理文件的位置。 (除非文件夹名称与 Microsoft.Net.Compilers 不同)

我原来的 package.config 文件有这一行
<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net462" developmentDependency="true" />

现在在 .csproj 文件中我有
   <PackageReference Include="Microsoft.Net.Compilers">
<Version>1.0.0</Version>
</PackageReference>

更新 1
因此,当启用 packagereference 时,nuget 将在 C:\Users\{username}\.nuget\packages 安装软件包。文件夹

这意味着我需要使用正确的相对路径更新 csproj 文件。

包文件夹的相对路径是什么?

最佳答案

由于将包管理格式设置为 PackageReference 会将包安装到全局 nuger 文件夹,即 C:\Users\{username}\.nuget\packages我不得不编辑 csproj 文件更新以下几行

csproj 顶部

<Import Project="$(UserProfile)\.nuget\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('$(UserProfile)\.nuget\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="$(UserProfile)\.nuget\packages\Microsoft.Net.Compilers\2.1.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props')" />

然后更新 csproj 底部的以下几行
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(UserProfile)\.nuget\packages\Microsoft.Net.Compilers\2.1.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '$(UserProfile)\.nuget\packages\Microsoft.Net.Compilers\2.1.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('$(UserProfile)\.nuget\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '$(UserProfile)\.nuget\packages\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>

以上内容仅供引用 NET Standard 1.4项目到 .NET 4.6.2。很烦人!!

关于visual-studio-2017 - Nuget 无法恢复 Microsoft.Net.Compilers.1.0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48754397/

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