我研究了这个问题,但没有一个解决办法有效。我安装了Visual Studio Professional 2015,我正在使用TFS。我的NuGet版本是3.1.6。这个问题只发生在我的c# Web API/MVC项目中。

我得到以下错误:

这个项目引用了NuGet包(s),这是缺失的 电脑。使用NuGet包还原来下载它们。更多的 信息,见http://go.microsoft.com/fwlink/?LinkID=322105。的 丢失的文件是 . . \ \ Microsoft.Net.Compilers.1.0.0 \制造\ Microsoft.Net.Compilers.props包

I do not have .nuget folder in my solutions. I have a packages folder in the solution and when I delete it, it seems like NuGet does rebuild the dependencies but the project still has the above error. I tried removing the project from TFS and it didn't fix it. Along with the above error, all the references in the project have yellow warning signs and say they are missing. When I checked the NuGet Package Manager for the project, everything that is "missing" has a green tick next to it, including Microsoft.Net.Compilers. I tried adding a new Web API/MVC project and it faced a similar problem where most references such as Owin were "missing" with the yellow warning sign.


我今天也犯了同样的错误(丢失了完全相同的包裹)。我还创建了一个MVC + Web API项目。

发生这种情况是因为我将应用程序文件(包括.csproj)文件移动到另一个位置。我手动更新了.sln文件,但所有包依赖项现在(Visual Studio 2015)存储在.csproj文件中。

编辑.csproj文件并更正解决方案文件夹(其中包含packages文件夹)的相对路径,为我解决了这个问题。

注意——这将更新整个解决方案的包,而不仅仅是项目。

如果你还有一个丢失的nuget包,在构建解决方案时给出错误,请使用以下命令,从工具> nuget包管理器>包管理器控制台使用nuget命令控制台。它将重新安装您的所有当前包。

Update-Package –reinstall

更新:

您可以将特定的项目名称作为参数传递。

Update-Package –reinstall -ProjectName SampleApp

我收到了这个令人沮丧的消息。最后对我有用的是删除/包内的所有文件和文件夹,让VS在下次构建时重新获取所有内容。

错误信息是完全正确的。我试了所有的花招,没有一个奏效。项目(简单的MVC Web应用程序测试)从Windows 8.1 VS 2015社区转移到我在Windows 10上的新测试箱。所有VS 2015的最新更新都适用。 我甚至无法安装任何更新版本的编译器包。

Loop:
<LOOP>This seems to be a Ground Hog Day phenomena.</LOOP>
GoTo Loop

我最终只是将Microsoft.Net.Compilers.1.0.0从旧项目复制到新项目中,它工作了。 然后我可以开始将其他包更新到新版本。 在我看来是nuget项目升级过程的bug。

注意:最初的项目是在VS 2015中创建的,没有任何遗留的nuget方法。

提比柳是正确的。我不得不编辑我的.csproj文件,因为文件被移动了,导致了这个问题

 <Import Project="..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />

我改变了文件的顶部和底部

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

我正在使用VS2012,遇到同样的错误。我从.csproj文件中删除了下面的Target标记,它开始编译,没有出现任何错误。

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  -- Error messages within Target Tag
</Target>

我通过从.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>

这两个答案的组合对我来说是有效的。首先,我修改了.csproj文件以删除对1.0.0版本的引用

< Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild" >

  ----Error---

< /Target>

然后真的

Update-Package -Reinstall

它成功了。

我找不到任何解决方案,所以我添加了一个nuget.exe副本和一个powershell脚本到解决方案的根目录,称为prebuild。Ps1的以下内容。

$nugetexe = 'nuget.exe'
$args = 'restore SOLUTION_NAME_HERE.sln'
Start-Process $nugetexe -ArgumentList $args

在我的构建中,我在预构建脚本路径中调用这个powershell脚本

对于在这里遇到我遇到的问题(在构建服务器上恢复了一些包,但不是所有包)的任何人来说,对我来说,难题的最后一块是添加NuGet。config在我的解决方案的根文件中,是. sln文件的兄弟,正如David Ebbo在这里解释的:http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html。

从Ebbo的博客文章来看,文件内容对我来说很简单

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </packageSources>
</configuration>

更新:

v3的NuGet API URL已更改(截至2016年9月)。从https://www.nuget.org/

<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />

对我来说,问题是当我将解决方案复制到一个新文件夹并打开它时,它缺少如下所示的Nuget文件夹。我复制了这个文件夹,一切正常。注意:这个文件夹在我们的源代码控制中,但不在这个解决方案项目中,它在上面一个目录中。

我的工作时,我复制包文件夹解决方案文件和项目文件夹。我只是没有复制包文件夹从以前的地方。

我通过从.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('..\..\..\Assemblies\NuGet\SpecFlow.Plus.Excel.1.4.2\build\SpecFlow.Plus.Excel.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\Assemblies\NuGet\SpecFlow.Plus.Excel.1.4.2\build\SpecFlow.Plus.Excel.targets'))" />

您还可以使用建议的错误消息作为提示。下面是如何找到解决方案的管理包,并单击解决丢失的nuget包。

就是这样

在我的案例中工作的解决方案- Visual Studio 2015 enterprise,项目.NET 4.6.1

升级至Update 3 安装Web开发工具

为了在这里展开一些答案,是的,你可以从你的.csproj文件中删除以下块:

<目标

这解决了问题,但在我的情况下,我注意到我有额外的引用。net。编译器和。codedom。不同版本的供应商:

<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.0.0
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\

<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\

当我的包裹。配置仅参考以下内容:

<package id="Microsoft.Net.Compilers" version="2.0.1"
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.3"

从.csproj文件中删除1.0.0项解决了这个问题。

只要启用NuGet包恢复。 右键单击您的解决方案>选择“启用NuGet包恢复”。

这将创建带有NuGet的. NuGet文件夹。配置文件,并解决了我的问题。

注释WebConfig中的编译器选项:

<!--<system.codedom>
<compilers>
  <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
  <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>-->

更新包配置文件中的最新版本

  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.4" targetFramework="net452" />

重建如果一切正常,不需要继续,否则 右键单击项目,点击“卸载项目” 再次右键单击该项目并编辑.csproj文件

验证Codedom的路径,它在之前的路径中没有net45,手动添加,保存,加载,重建。它应该会起作用。

<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.4\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.4\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />

正如许多人建议的那样,删除<Target>标记可以使其可编译。然而,当您为测试项目这样做时,要注意它有一个副作用。

我得到了与MSTest相关的错误。TestAdapter nuget包在编译时。通过移除<Target>标签解决了这个问题。尽管它使构建成功,但测试方法变得不可发现。测试资源管理器不会列出该项目中的测试方法,运行测试或调试测试也不能很好地工作。

我在使用Visual Studio 2017和.Net框架4.7时遇到了这种情况,在其他版本中也很可能发生这种情况

我的问题是NuGet不能自动获取/更新包,因为完整的文件路径太大了。通过将我的解决方案移动到我的文档中的一个文件夹而不是一个深度嵌套的文件夹来修复。

然后可以右键单击解决方案并选择“恢复NuGet包”(如果您只是构建它并让它为您完成它,这可能是不必要的),然后选择“管理解决方案的NuGet包”以将所有包更新到最新版本。

这是从微软网站上下载的一个ASP MVC应用程序示例的解决方案。

对于DevOps/构建工程师,您可能可以针对受影响的SLN或缺乏SLN的项目修复此运行nuget恢复。我必须为我们所有UWP项目的CI/CD构建这样做。

Make sure nuget is installed on the build slave either in Visual Studio or standalone. If it's the latter, make sure it's in PATH and skip step 2. Either open the VS Dev CMD console, or load it via an already open one, which you can do with the instructions below: VS2015 call "%VS140COMNTOOLS%VsDevCmd.bat" or VS2017 call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" call nuget restore MyStuff.SLN or call nuget restore MyStuff.csproj if there's no SLN.

对我来说,包在正确的路径下,但是包文件夹中的构建文件夹不是。我只是删除了它所说的所有丢失的包并重新构建解决方案,它成功地创建了构建文件夹和.props文件。所以错误消息是正确的,它告诉我有什么东西漏了。

Not sure if this will help anyone, but I had this issue come up when I deleted the source code from my local machine without having ever saved the solution file to TFS. (During initial development, I was right-clicking and checking in the project in Solution Explorer, but forgot to ever check in the solution itself.) When I needed to work on this again, all I had in TFS was the .csproj file, no .sln file. So in VS I did a File --> Source Control --> Advanced -- Open from Server and opened the .csproj file. From there I did a Save All and it asked me where I wanted to save the .sln file. I was saving this .sln file to the project directory with the other folders (App_Data, App_Start, etc.), not the top level directory. I finally figured out that I need to save the .sln file up a directory from the project folder so it's on the same level as the project folder. All my paths resolved and I was able to build it again.

当从Git部署时,我在Azure中失败地构建了这个问题。

原来我的.gitignore从..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props中排除了build文件夹。

一旦构建文件夹(强制)提交到Git,问题就解决了。

对我来说,我的gitignore文件忽略了我的包文件夹。下面的gitignore线引起的问题-

**/packages/*

删除并恢复我的包文件夹。希望这能帮助到其他人。

我得到了这个错误的修复,实际上我有一个不同版本的MSTest.TestAdapter(1.3.2)在我的包文件夹和在.csproj文件引用指向MSTest.TestAdapter(1.1.0)。我已经将所有MSTest.TestAdapter(1.1.0)替换为MSTest.TestAdapter(1.3.2),这解决了我的问题。

我知道这个问题很老了,但是我今天遇到了同样的情况,我想为最近发现这个问题的人提供我的2美分。我手动移动到解决方案中的一个子文件夹,然后使用Visual Studio 2017删除并读取到解决方案的一个ASP MVC项目给出了上述错误。移动“lib”和“packages”文件夹到同一子文件夹的根MVC项目修复了我的问题。

我也遇到了同样的问题,原来我引用的一个项目在解决方案目录之外(因此没有共享相同的“/packages”文件夹)。对我来说有效的解决方案是打开参考项目的解决方案并在那里构建它。一旦项目建成,错误就消失了。

这种方法解决了我的错误: 在Visual Studio 2015+解决方案资源管理器中打开.csproj文件进行更新:

右键单击项目名称->卸载项目

右键单击项目名称->编辑.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('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
    <Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
    <Error Condition="!Exists('packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
    <Error Condition="!Exists('packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
  </Target>

右键单击项目名称->重新加载项目

最后构建解决方案。

注释掉.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('..\packages\Costura.Fody.2.0.1\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.2.0.1\build\Costura.Fody.targets'))" />
<Error Condition="!Exists('..\packages\Fody.3.1.3\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.3.1.3\build\Fody.targets'))" />

解决方案中的文件夹名为”。网络项目”。通过将其重命名为“NET Project”,一切都很正常。所以一开始的点是个坏主意。

在我的例子中,*中缺少<RestorePackages>true</RestorePackages>。csproj文件。没有必要删除我在前面的回答中看到的代码片段。

不同的用户名是常见的原因,Nuget下载一切到:“C:\Users\USER_NAME\source\repos”,如果你之前在不同的用户名上设置了项目。csproj文件可能仍然包含旧的用户名,只需打开它,并做一个搜索替换“C:\Users\ old_user_name \source\repos”到“C:\Users\NEW_USER_NAME\source\repos”。

这似乎有多种原因。

对于我来说,.csproj文件包含了对Microsoft.Bcl.Build.targets两个不同版本的引用:

<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
    <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="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=317567." HelpKeyword="BCLBUILD2001" />
    <Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>


<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<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('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>

我删除了旧的参考,它解决了这个问题。

如果使用package,也会得到这个错误。与此构建命令一起配置

MSBuild.exe /t:Restore MySln.sln

在这种情况下,要么切换到nuget恢复命令,要么使用PackageReference。

我用以下步骤解决了同样的问题

Removed package <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net46" /> from package.config file. Edit the .csproj project file and removed the below settings. <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('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />   </Target> Go to package manager console and run the command Update-Package –reinstall

第2点和第3点是其他用户提出的,我很感谢这些用户。第一点,从包中删除Microsoft.CodeDom.Providers.DotNetCompilerPlatform。配置文件更重要。此外,在运行第3点中提到的命令之后,问题就解决了。删除所有不需要的包并更新所需的包引用。

希望这能帮助到一些人。

0

对于nuget引用,我们可以通过引用或通过包添加a。配置文件。

在Visual Studio 2017中,字母顺序或nuget引用由VS自动处理。

但是在Visual Studio 2019中。如果你的nuget引用不是按字母顺序排列的,那么VS就不要在引用文件夹中加载文件。

为了解决这个问题。——删除.csproj/vbproj或package.config中的所有引用。

——保存在记事本中。尝试通过Nuget包管理器添加这些。

第一次试试。一旦安装。

—右键单击解决方案->恢复所有nuget包。

-你会看到它加载了一个nuget引用。

——现在一个一个做。

——如果你100%确定你的参考文献是按字母顺序排列的。只需将它们全部粘贴到.csproj/vbproj或package.config中即可。

—恢复溶液中的所有核。

你会看到所有的符号都将被加载。在解决方案资源管理器的顶部图标刷新你的引用文件夹。

快乐的引用。

遇到这个问题

按以下步骤求解

清除packages文件夹中的内容(先备份) 使用“更新-包-重新安装”从包管理控制台的NuGet中重新获取和重新安装包(Tools -> NuGet包管理器->包管理控制台) 从.csproj文件中删除冗余路径。注意:NuGet会添加新的路径到csproj文件,但它不会删除旧的路径… (有一些机会csproj文件有多个路径为同一文件)

为什么我们需要“Microsoft.Net.Compilers.props”? 它将提供“\roslyn”文件夹。如果没有它,你可能仍然可以编译程序,但不能使用@{html.RenderPartial…}