VBC Fatal error BC2000: Project already has a reference to assembly

时间秒杀一切 提交于 2019-12-12 18:06:14

问题


I've researched this issue for a few days with no answer. There are references to the error code but I believe that BC2000 is used for all "compiler initialization" errors, regardless of the underlying issue.

I have a VS solution that compiles just fine in our dev environment with MSBuild 12.0. However, when trying to compile in our Win 2008 R2 SP1 build machine using MSBuild 12.0, we get a fatal error.

The command being executed for MSBuild is:

"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" "path\to\solution.sln" /target:Clean;Build /verbosity:normal /toolsversion:12.0 /nologo /property:WarningLevel="2" /property:Configuration="Release"

The error received is:

vbc: Error: Fatal error BC2000 : compiler initialization failed unexpectedly: Project already has a reference to assembly Microsoft.VisualBasic. A second reference to 'path\to\dotnet4\System.dll' cannot be added. (Fatal error BC2000)

This is similar to this question. However, we don't have the setup their using as we're not using Mono.

The project in question has only one reference to Microsoft.VisualBasic assembly. Also, the vbc commands being executed are similar in the dev and build machines, and they only refer to the mentioned assembly once.

Same for dev and build machines:

  • .NET Framework version: 4.6.1
  • MSBuild being used: 12.0

Different:

  • Dev machines have either VS 2010 or VS 2013.
  • Build machine does not have VS installed.
  • Build machine also has MS Visual C++ Build Tools 2015 installed.

Has anybody come across this issue before? Any ideas on how to fix it? Thanks.


回答1:


When running the build in the dev machine, I checked the vbc command (huge, so I won't post) and it was linking to Microsoft.VisualBasic.dll in the following folder:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0

I noticed that this folder was not available in the build machine, as it did not have the .Net Framework 4 SDK. So I installed the "Microsoft Windows SDK for Windows 7 and .NET Framework 4" (yes, even though the build machine as Win 2008 R2) and it worked.

Now, to install that SDK, I had to first uninstall the .Net Framework because it was a newer version, then install .Net Framework 4 and then the mentioned SDK, and then update again to .Net Framework 4.6.1.

So, in summary:

  1. Execute MSBuild in the build machine and redirect output to a log file
  2. Open the log file and check the vbc command that failed
  3. Execute MSBuild in the dev machine and redirect output to a log file
  4. Open the log file and locate the command identified in step 2
  5. Check where the assembly in question (from the error) is located
  6. If it's a directory similar to what I said at the beginning, then maybe you need to install the SDK for the .Net Framework of the said version. In my case, the directory had that v4.0 so it was for .Net Fw 4.0.

Hopefully this helps someone else out there.



来源:https://stackoverflow.com/questions/34864258/vbc-fatal-error-bc2000-project-already-has-a-reference-to-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!