.net 构建错误,此项目引用 NuGet

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34465376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 09:44:56  来源:igfitidea点击:

Build error, This project references NuGet

.netvisual-studionugetnuget-package-restore

提问by Bryan

When I try to build my solution, I get the following error message:

当我尝试构建我的解决方案时,我收到以下错误消息:

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.1.1\build\Microsoft.Net.Compilers.props. MusicKarma C:\Users\Bryan\Documents\Visual Studio 2015\Projects\MusicKarma\MusicKarma.csproj 268

严重性代码说明项目文件行抑制状态错误此项目引用了此计算机上缺少的 NuGet 包。使用 NuGet Package Restore 来下载它们。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105。丢失的文件是 ..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props。MusicKarma C:\Users\Bryan\Documents\Visual Studio 2015\Projects\MusicKarma\MusicKarma.csproj 268

When I look In my packages folder, I can find I file named Microsoft.Net.Compilers.props

当我查看我的包文件夹时,我可以找到名为 Microsoft.Net.Compilers.props 的文件

I have tried to use Nuget Restore, but it keeps saying that I have all the packages.

我曾尝试使用 Nuget Restore,但它一直说我拥有所有软件包。

This happens when I take this project from TFS to one of my computers.

当我将这个项目从 TFS 带到我的一台计算机时,就会发生这种情况。

采纳答案by Matt Ward

First I would check if your MusicKarma project has Microsoft.Net.Compilers in its packages.config file. If not then you could remove everything to do with that NuGet package from your MusicKarma.csproj.

首先,我会检查您的 MusicKarma 项目在它的 packages.config 文件中是否有 Microsoft.Net.Compilers。如果没有,那么您可以从 MusicKarma.csproj 中删除与该 NuGet 包有关的所有内容。

If you are using the Microsoft.Net.Compilers NuGet package then my guess is that the path is incorrect. Looking at the directory name in the error message I would guess that the MusicKarma solution file (.sln) is in the same directory as the MusicKarma.csproj. If so then the packages directory is probably wrong since by default the packages directory would be inside the solution directory. So I am assuming that your packages directory is:

如果您使用的是 Microsoft.Net.Compilers NuGet 包,那么我的猜测是路径不正确。查看错误消息中的目录名称,我猜测 MusicKarma 解决方案文件 (.sln) 与 MusicKarma.csproj 位于同一目录中。如果是这样,那么包目录可能是错误的,因为默认情况下包目录将在解决方案目录中。所以我假设你的包目录是:

C:\Users\Bryan\Documents\Visual Studio 2015\Projects\MusicKarma\packages

Whilst your MusicKarma.csproj file is looking for the props file in:

虽然您的 MusicKarma.csproj 文件正在寻找以下道具文件:

C:\Users\Bryan\Documents\Visual Studio 2015\Projects\packages\Microsoft.Net.Compilers.1.1.1\build

So if that is the case then you can fix the problem by editing the path in your MusicKarma.csproj file or by reinstalling the NuGet package.

因此,如果是这种情况,那么您可以通过编辑 MusicKarma.csproj 文件中的路径或通过重新安装 NuGet 包来解决问题。

回答by Kevin Candlert

This problem appeared for me when I was creating folders in the filesystem (not in my solution) and moved some projects around.

当我在文件系统中(不在我的解决方案中)创建文件夹并移动一些项目时,这个问题出现在我身上。

Turns out that the package paths are relative from the csproj files. So I had to change the "HintPath" of my references:

事实证明,包路径是相对于 csproj 文件的。所以我不得不改变我的参考文献的“HintPath”:

<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
    <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
    <Private>True</Private>
</Reference>

To:

到:

<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
    <HintPath>..\..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
    <Private>True</Private>
</Reference>

Notice the double "..\" in 'HintPath'.

注意'HintPath' 中的双“..\”。

I also had to change my error conditions, for example I had to change:

我还必须更改我的错误条件,例如我必须更改:

<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props'))" />

To:

到:

<Error Condition="!Exists('..\..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props'))" />

Again, notice the double "..\".

再次注意双“..\”。

回答by Natasha Voloshyna

Quick solution that worked like a charm for me and others:

对我和其他人来说就像一个魅力的快速解决方案:

If you are using VS 2015+, just remove the following lines from the .csproj file of your project:

如果您使用的是 VS 2015+,只需从项目的 .csproj 文件中删除以下几行:

  <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable 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('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
  </Target>

In VS 2015+ Solution Explorer:

在 VS 2015+ 解决方案资源管理器中:

  1. Right-click project name -> Unload Project
  2. Right-click project name -> Edit .csproj
  3. Remove the lines specified above from the file and save
  4. Right-click project name -> Reload Project
  1. 右键单击项目名称 -> 卸载项目
  2. 右键单击项目名称 -> 编辑 .csproj
  3. 从文件中删除上面指定的行并保存
  4. 右键单击项目名称 -> 重新加载项目

回答by Joana Brand?o

I also had this error I took this part of code from .csproj file:

我也有这个错误我从 .csproj 文件中提取了这部分代码:

 <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
      <PropertyGroup>
        <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable 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('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
    </Target>

回答by andreyfromnn

Why should you need manipulations with packages.config or .csproj files?
The error explicitly says: Use NuGet Package Restore to download them.
Use it accordingly this instruction: https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore-troubleshooting:

为什么需要对 packages.config 或 .csproj 文件进行操作?
错误明确指出:使用 NuGet 包还原来下载它们。
相应地使用此说明:https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore-troubleshooting

Quick solution for Visual Studio users
1.Select the Tools > NuGet Package Manager > Package Manager Settings menu command.
2.Set both options under Package Restore.
3.Select OK.
4.Build your project again.

Visual Studio 用户的快速解决方案
1. 选择工具 > NuGet 包管理器 > 包管理器设置菜单命令。
2. 在 Package Restore 下设置这两个选项。
3.选择确定。
4.再次构建您的项目。

回答by Ravimaran

It's a bit old post but I recently ran into this issue. All I did was deleted all the nuget packages from packages folder and restored it. I was able to build the solution successfully. Hopefully helpful to someone.

这是一个有点旧的帖子,但我最近遇到了这个问题。我所做的只是从包文件夹中删除了所有 nuget 包并恢复了它。我能够成功构建解决方案。希望对某人有帮助。