我研究了这个问题,但没有一个解决办法有效。我安装了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应用程序测试)从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'))" />
对于在这里遇到我遇到的问题(在构建服务器上恢复了一些包,但不是所有包)的任何人来说,对我来说,难题的最后一块是添加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" />
为了在这里展开一些答案,是的,你可以从你的.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项解决了这个问题。
注释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=\"Web\" /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')" />
对于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.
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.
这种方法解决了我的错误:
在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文件包含了对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>
我删除了旧的参考,它解决了这个问题。
我用以下步骤解决了同样的问题
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中即可。
—恢复溶液中的所有核。
你会看到所有的符号都将被加载。在解决方案资源管理器的顶部图标刷新你的引用文件夹。
快乐的引用。