简体   繁体   English

找不到部分路径... bin\roslyn\csc.exe

[英]Could not find a part of the path ... bin\roslyn\csc.exe

I am trying to run an ASP.NET MVC (model-view-controller) project retrieved from TFS (Team Foundation Server) source control.我正在尝试运行从 TFS (Team Foundation Server) 源代码管理中检索到的 ASP.NET MVC(模型-视图-控制器)项目。 I have added all assembly references and I am able to build and compile successfully without any error or warning.我已经添加了所有程序集引用,并且能够在没有任何错误或警告的情况下成功构建和编译。

But I get the following error in the browser:但是我在浏览器中收到以下错误:

Could not find a part of the path 'C:\B8akWorkspace\B8akProject\B8akSolution\B8AK.Portal\bin\roslyn\csc.exe'.找不到路径“C:\B8akWorkspace\B8akProject\B8akSolution\B8AK.Portal\bin\roslyn\csc.exe”的一部分。

Here is a full screenshot of the error page.这是错误页面的完整屏幕截图。

在此处输入图像描述

After few days of research, I understood that Roslyn is a .NET compiler platform that offers advanced compiling features.经过几天的研究,我了解到Roslyn是一个提供高级编译功能的 .NET 编译器平台。 However, I do not understand why my build is trying to find \bin\roslyn\csc.exe because I did not configure anything related to Roslyn.但是,我不明白为什么我的构建试图找到 \bin\roslyn\csc.exe,因为我没有配置与 Roslyn 相关的任何内容。 Nor did I intend to use Roslyn in my project.我也不打算在我的项目中使用 Roslyn。

TL; TL; DR博士

run this in the Package Manager Console:在包管理器控制台中运行它:

Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r

More information更多信息

This problem is not related to Visual Studio itself, so answers suggesting adding build steps to copy files over are rather a workaround.此问题与 Visual Studio 本身无关,因此建议添加构建步骤以复制文件的答案是一种解决方法。 Same with adding compiler binaries manually to the project.与手动将编译器二进制文件添加到项目中相同。

The Roslyn compiler comes from a NuGet package and there is/was a bug in some versions of that package (I don't know exactly which ones). Roslyn 编译器来自 NuGet 包,并且该包的某些版本中存在/曾经存在错误(我不确切知道哪些版本)。 The solution is to reinstall/upgrade that package to a bug-free version.解决方案是将该软件包重新安装/升级到无错误版本。 Originally before I wrote the answer back in 2015 I fixed it by installing following packages at specific versions:最初在我在 2015 年写下答案之前,我通过在特定版本中安装以下软件包来修复它:

  • Microsoft.Net.Compilers 1.1.1 Microsoft.Net.Compilers 1.1.1
  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.1 Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.1

Then I looked into .csproj and made sure that the paths to packages are correct (in my case ..\..\packages\*.*) inside tags <ImportProject> on top and in <Target> with name "EnsureNuGetPackageBuildImports" on the bottom.然后我查看了 .csproj 并确保包的路径是正确的(在我的情况下是 ..\..\packages\*.*)在顶部的标签<ImportProject>和名称为“EnsureNuGetPackageBuildImports”的<Target>中底部。 This is on MVC 5 and .NET Framework 4.5.2.这是在 MVC 5 和 .NET Framework 4.5.2 上。

The problem with the default VS2015 templates is that the compiler isn't actually copied to the tfr\bin\roslyn\ directory, but rather the {outdir}\roslyn\ directory默认 VS2015 模板的问题是编译器实际上并没有复制到tfr\bin\roslyn\目录,而是{outdir}\roslyn\目录

Add this code in your .csproj file:将此代码添加到您的 .csproj 文件中:

<Target Name="CopyRoslynFiles" AfterTargets="AfterBuild" Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'">
    <ItemGroup>
      <RoslynFiles Include="$(CscToolPath)\*" />
    </ItemGroup>
    <MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" />
    <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
</Target>

清洁和重建对我有用!

Your build is trying to find \bin\roslyn\csc.exe because the following packages have been added to your project.您的构建正在尝试查找\bin\roslyn\csc.exe ,因为以下软件包已添加到您的项目中。 Just review your packages.config file, you can have both of them there只需查看您的packages.config文件,您可以同时拥有它们

Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers

What is Roslyn and Who added them(packages) in the project : If you're using .net Framework 4.5.2 to create projects using VS2015, you might have noticed that the project templates use Roslyn by default.什么是 Roslyn 以及谁在项目中添加了它们(包):如果您使用 .net Framework 4.5.2 使用 VS2015 创建项目,您可能已经注意到项目模板默认使用 Roslyn。 Actually, Roslyn is one of open-source compilers for .NET languages from Microsoft.实际上,Roslyn 是 Microsoft 的 .NET 语言的开源编译器之一。

Why should we delete Roslyn : If your project has Roslyn references and you are interested to deploy it on server, you will get unwanted errors on the website as many hosting providers still have not upgraded their servers and hence do not support Roslyn.我们为什么要删除 Roslyn :如果您的项目有 Roslyn 引用并且您有兴趣将其部署在服务器上,您将在网站上收到不需要的错误,因为许多托管服务提供商仍未升级其服务器,因此不支持 Roslyn。 To resolve this issue, you will need to remove the Roslyn compiler from the project template.要解决此问题,您需要从项目模板中删除 Roslyn 编译器。

if you are not interested in using Roslyn, follow steps bellow to delete it如果您对使用 Roslyn 不感兴趣,请按照以下步骤将其删除

1. Remove NuGet packages, use the following commands from Nuget Package Console 1.删除 NuGet 包,使用 Nuget 包控制台中的以下命令

PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
PM> Uninstall-package Microsoft.Net.Compilers

2. After you do this, your web.config file should be auto-updated. 2.完成此操作后,您的 web.config 文件应该会自动更新。 In case it is not, look for the below code in web.config file and if it is found, delete this piece of code.如果不是,请在web.config文件中查找以下代码,如果找到,请删除这段代码。

<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>
      <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+"></compiler>
    </compilers>
</system.codedom>

Here is a more MSBuild way of doing this.这是执行此操作的更多 MSBuild 方式。

<Target Name="CopyRoslynFiles" AfterTargets="AfterBuild" Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'">
    <ItemGroup>
      <RoslynFiles Include="$(CscToolPath)\*" />
    </ItemGroup>
    <MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" />
    <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
</Target>

But I notice that the roslyn files are also in my bin directory (not in a folder).但我注意到 roslyn 文件也在我的 bin 目录中(而不是在文件夹中)。 The app seems to work, though.不过,该应用程序似乎可以工作。

Too late for an answer but still posting incase it helps anyone.答案为时已晚,但仍然发布它可以帮助任何人。
Following the below steps fixed the error for me:按照以下步骤为我修复了错误:

  1. delete packages folder删除包文件夹
  2. open VS打开VS
  3. rebuild重建
  4. observe that NuGet packages are restored, but bin\roslyn isnt created观察 NuGet 包已恢复,但 bin\roslyn 未创建
  5. unload project卸载项目
  6. reload project重新加载项目
  7. rebuild重建
  8. observe that the bin\roslyn has been created now.观察 bin\roslyn 现在已创建。

As noted in an issue in the Roslyn project on GitHub , a solution (that worked for me) is to simply unload and reload the project in Visual Studio.正如GitHub 上 Roslyn 项目中的一个问题所述,一个解决方案(对我有用)是在 Visual Studio 中简单地卸载和重新加载项目。

The "bin\roslyn" folder wasn't created on build or rebuild until I reloaded the project.在我重新加载项目之前,不会在构建或重建时创建“bin\roslyn”文件夹。

0. The quick fix 0. 快速修复

As already noted in the currently highest voted answer , the quick fix is to use the package manager, Tools > Nuget Package Manager > Package Manager Console , to run正如在当前投票率最高的答案中已经指出的那样,快速修复是使用包管理器Tools > Nuget Package Manager > Package Manager Console来运行

Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r

Packet Manager Console - how to open

1. Code to reproduce the error 1.重现错误的代码

Here is code that reproduces the error:这是重现错误的代码:
https://user.it.uu.se/%7Ehesc0353/SrvrErr-reproduce.zip https://user.it.uu.se/%7Ehesc0353/SrvrErr-reproduce.zip
(Originally from https://github.com/aspnet/AspNetDocs/tree/master/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client/sample/server/ProductsApp ) (原文来自https://github.com/aspnet/AspNetDocs/tree/master/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client/sample/server/ProductsApp )

Consider trying the example code provided in the zip file above.考虑尝试上面 zip 文件中提供的示例代码。
If no changes are made, Ctrl + F5 will reproduce the error.如果未进行任何更改, Ctrl + F5将重现错误。

Server Error '/' in Application

2. A more robust solution 2. 更强大的解决方案

An alternative solution is to remove an attribute from the project's Web.config file.另一种解决方案是从项目的Web.config文件中删除一个属性。
( Web.config is in the same directory as the .csproj file.) Web.config.csproj文件位于同一目录中。)
This will automatically and silently recreate your packages if they are missing.如果它们丢失,这将自动且静默地重新创建您的包。

Open the Web.config file in a text editor or in Visual Studio.在文本编辑器或 Visual Studio 中打开Web.config文件。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings></appSettings>
  ...
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /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.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
</configuration>

In the tag configuration > system.codedom > compilers > compiler language="c#;cs;csharp" , completely remove the type attribute.在标签配置> system.codedom > compilers > compiler language="c#;cs;csharp"中,完全移除type属性。 – In short, remove the line that starts with type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, . 1 – 简而言之,删除以type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, . 1开头的行

Visual Studio will take care of the rest. Visual Studio 将负责其余的工作。 – No more Server Error in '/' Application . Server Error in '/' Application

3. HTTP Error 403 3. HTTP 错误 403

In the example provided above, hitting Ctrl + F5 will now result in an HTTP Error 403 .在上面提供的示例中,现在按 Ctrl + F5将导致HTTP 错误 403

HTTP Error 403.14 - Forbidden

Try replacing http://localhost:64195 in your web browser with http://localhost:64195/api/products .尝试将 Web 浏览器中的 http://localhost: http://localhost:64195替换为http://localhost:64195/api/products The web API now displays correctly: Web API 现在可以正确显示:

A web API containing products


As a provocation, I tried removing the whole package directory from the Visual Studio project.作为一种挑衅,我尝试从 Visual Studio 项目中删除整个package目录。
It was automatically and silently recreated as soon as the project was rebuilt.项目一重建,它就会自动、静默地重建。

References参考


1 Presumably, the same fix works for Visual Basic as well as for C#, but I haven't tried it. 1据推测,相同的修复程序适用于 Visual Basic 和 C#,但我还没有尝试过。

I followed these steps and it worked perfectly我按照这些步骤操作,效果很好

  • Delete all the bin and obj folders删除所有 bin 和 obj 文件夹
  • Clean solution and rebuild清理解决方案并重建
  • Run this command in powershell在 powershell 中运行此命令

Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r

I was also having same issue while running the project.我在运行项目时也遇到了同样的问题。 Here are the steps that I followed.这是我遵循的步骤。

  1. Right click in solution右键单击解决方案
  2. select Clean solution选择清洁解决方案
  3. After clean succeeded,Again build your project清理成功后,再次构建您的项目
  4. Run the project again再次运行项目

This time I didn't see the same error.这次我没有看到同样的错误。 This works as expected.这按预期工作。

After trying all of the fixes with no cigar I fixed it by updating this Nuget Package in Visual Studios:在尝试了所有没有雪茄的修复后,我通过在 Visual Studios 中更新这个 Nuget 包来修复它:

Microsoft.CodeDom.Providers.DotNetCompilerPlatform Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Mine was from 1.0.0 to 2.0.0 for reference (The error no longer shows)我的是从 1.0.0 到 2.0.0 供参考(错误不再显示)

  1. Clean Solution清洁解决方案
  2. Rebuild Solution ,These two steps worked for me.重建解决方案,这两个步骤对我有用。

For VS 2019 remove the following node completely:对于 VS 2019,完全删除以下节点:

<system.codedom>
</system.codedom>

NuGet 包管理器

You need to install Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix, was especially created for that error您需要安装 Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix,专为该错误创建

  • Right click on your project and select Manage Nuget Packages右键单击您的项目并选择管理 Nuget 包
  • Find "Microsoft.CodeDom.Providers.DotNetCompilerPlatform"找到“Microsoft.CodeDom.Providers.DotNetCompilerPlatform”
  • Simply Update to an older or newer version (doesn't matter which), and then update again back to your original version.只需更新到较旧或较新的版本(不管哪个),然后再次更新回您的原始版本。

This re-installs all the dependencies and files of the package (like csc.exe)这将重新安装包的所有依赖项和文件(如 csc.exe)

Nuget - DotNetCompilerPlatform

In my case, before trying any of the other solutions, I switched to a "Release" configuration, rebuilt (the folder got created) and then switched back to "Debug", while the folder remained intact.就我而言,在尝试任何其他解决方案之前,我切换到“发布”配置,重建(文件夹已创建),然后切换回“调试”,而文件夹保持不变。

This was a checkout from source control of an older solution and apparently the original (automatic) package restore and building the project didn't create that folder in the bin directory.这是从旧解决方案的源代码控制中签出的,显然原始(自动)包还原和构建项目并未在 bin 目录中创建该文件夹。

Note that at time of writing this, the blamed component has reached v.2.请注意,在撰写本文时,被指责的组件已达到 v.2。

更新 nuget 包对我有用 右键单击​​解决方案 > 管理 NuGet 包以获取解决方案并更新所有包,特别是: Microsoft.Net.CompilersMicrosoft.CodeDom.Providers.DotNetCompilerPlatform

So, Rob Cannon's answer essentially worked for me, but I had to tweak a handful of the options.所以, Rob Cannon 的回答基本上对我有用,但我不得不调整一些选项。 Specifically, I had to remove the condition on the target, as well as change the Include attribute, as $CscToolPath was empty when the project was being built on our build server.具体来说,我必须删除目标上的条件,并更改 Include 属性,因为在我们的构建服务器上构建项目时,$CscToolPath 是空的。 Curiously, $CscToolPath was NOT empty when running locally.奇怪的是,在本地运行时 $CscToolPath 不是空的。

<Target Name="CopyRoslynFiles" AfterTargets="AfterBuild" >
  <ItemGroup>
    <RoslynFiles Include="$(SolutionDir)packages\Microsoft.Net.Compilers.1.1.1\tools\*" />
  </ItemGroup>
  <MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" />
  <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
</Target>

This is a known issue with Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.6.这是Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.6 的一个已知问题 Downgrading to 1.0.5 fixed this for me.降级到 1.0.5 为我解决了这个问题。

In my case I have had issue in Jenkins when it tried to deploying it in Octopus with following error:就我而言,当 Jenkins 尝试在 Octopus 中部署它时遇到以下错误:

MSBUILD : OctoPack error OCT-1676060969: Failed to build the path for '\bin\roslyn\csc.exe' relative to 'T:\workspace\machine.engine\Machine.engine.Test': Invalid URI: The format of the URI could not be determined.. See the inner exception for more details. [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969: System.Exception: Failed to build the path for '\bin\roslyn\csc.exe' relative to 'T:\workspace\machine.engine\Machine.engine.Test': Invalid URI: The format of the URI could not be determined.. See the inner exception for more details. ---> System.UriFormatException: Invalid URI: The format of the URI could not be determined. [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at System.Uri..ctor(String uriString) [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at OctoPack.Tasks.Util.OctopusPhysicalFileSystem.GetPathRelativeTo(String fullPath, String relativeTo) in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\Util\OctopusPhysicalFileSystem.cs:line 211 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    --- End of inner exception stack trace --- [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at OctoPack.Tasks.Util.OctopusPhysicalFileSystem.GetPathRelativeTo(String fullPath, String relativeTo) in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\Util\OctopusPhysicalFileSystem.cs:line 224 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at OctoPack.Tasks.CreateOctoPackPackage.AddFiles(XContainer nuSpec, IEnumerable`1 sourceFiles, String sourceBaseDirectory, String targetDirectory, String relativeTo) in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\CreateOctoPackPackage.cs:line 443 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969:    at OctoPack.Tasks.CreateOctoPackPackage.Execute() in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\CreateOctoPackPackage.cs:line 190 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
Done Building Project "T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj" (default targets) -- FAILED

Cause原因

After spending some time, I was using an internal developed component that was using Microsoft.Net.Compilers .花了一些时间后,我使用了一个内部开发的组件,该组件正在使用Microsoft.Net.Compilers The reason the internal component was using Microsoft.Net.Compilers was to overcome this issue ( C#: throw invalid expression compilation ) and was solved this way ( How to use C# 7 with Visual Studio 2015? ).内部组件使用Microsoft.Net.Compilers的原因是为了克服这个问题( C#: throw invalid expression compilation )并以这种方式解决( How to use C# 7 with Visual Studio 2015? )。 This result in, when I installed the component on the main program, the Microsoft.Net.Compilers get added it selves automatically.这导致,当我在主程序上安装组件时, Microsoft.Net.Compilers会自动添加它。

Solution解决方案

My work around was, uninstall following from our internal component by (following @malikKhalil answer)我的解决方法是,从我们的内部组件中卸载(按照@malikKhalil 回答)

PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
PM> Uninstall-package Microsoft.Net.Compilers

And chose C# 7 compiler in Jenkins instead of C# 6 and rebuild, this is to ensure everything is working and building correctly.并在 Jenkins 中选择 C# 7 编译器而不是 C# 6 并重新构建,这是为了确保一切正常工作和构建。

Than finally in my main program I tried to update my internal component.最后,在我的主程序中,我尝试更新我的内部组件。 And everything than build again.一切都比重新构建。 It has built without any problems or issues.它的构建没有任何问题或问题。

Per a comment by Daniel Neel above :根据上面 Daniel Neel 的评论:

version 1.0.3 of the Microsoft.CodeDom.Providers.DotNetCompilerPlatform Nuget package works for me, but version 1.0.6 causes the error in this question Microsoft.CodeDom.Providers.DotNetCompilerPlatform Nuget 包的 1.0.3 版适用于我,但 1.0.6 版会导致此问题中的错误

Downgrading to 1.0.3 resolved this issue for me.降级到 1.0.3 为我解决了这个问题。

In my case I just needed to go to the bin directory in Visual Studio Solution Explorer (web application project) and include the roslyn project directly.在我的情况下,我只需要转到 Visual Studio 解决方案资源管理器(Web 应用程序项目)中的 bin 目录并直接包含 roslyn 项目。 By right clicking the folder and selecting Include In Project.通过右键单击文件夹并选择包含在项目中。 And check in the solution again to trigger the build process.并再次签入解决方案以触发构建过程。

The roslyn folder was not included by default.默认情况下不包括 roslyn 文件夹。

Microsoft.CodeDom.Providers.DotNetCompilerPlatform从 1.0.0 升级到 1.0.1 为我解决了这个问题。

If you were adding ASPNETCOMPILER to compile your Razor views in MVC, like in this StackOverflow question , then change PhysicalPath to place where Roslyn nuget package is located (usually pointed via $CscToolPath variable):如果您在 MVC 中添加 ASPNETCOMPILER 来编译 Razor 视图,就像在这个 StackOverflow question中一样,然后将 PhysicalPath 更改为 Roslyn nuget 包所在的位置(通常通过$CscToolPath变量指向):

<Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(CscToolPath)" />

就我而言,只需删除 bin 文件夹中的所有内容并重新编译即可为我完成所有工作。

The problem with the default VS2015 templates is that the compiler isn't actually copied to the {outdir}_PublishedWebsites\tfr\bin\roslyn\ directory, but rather the {outdir}\roslyn\ directory.默认 VS2015 模板的问题在于编译器实际上并未复制到{outdir}_PublishedWebsites\tfr\bin\roslyn\目录,而是{outdir}\roslyn\目录。 This is likely different from your local environment since AppHarbor builds apps using an output directory instead of building the solution "in-place".这可能与您的本地环境不同,因为AppHarbor使用输出目录构建应用程序,而不是“就地”构建解决方案。

To fix it, add the following towards end of .csproj file right after xml block <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">...</Target>要修复它,请在 xml 块<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">...</Target>之后将以下内容添加到.csproj文件的末尾

<PropertyGroup>
  <PostBuildEvent>
    if not exist "$(WebProjectOutputDir)\bin\Roslyn" md "$(WebProjectOutputDir)\bin\Roslyn"
    start /MIN xcopy /s /y /R "$(OutDir)roslyn\*.*" "$(WebProjectOutputDir)\bin\Roslyn"
  </PostBuildEvent>
</PropertyGroup>

Reference: https://support.appharbor.com/discussions/problems/78633-cant-build-aspnet-mvc-project-generated-from-vstudio-2015-enterprise参考:https: //support.appharbor.com/discussions/problems/78633-cant-build-aspnet-mvc-project-generated-from-vstudio-2015-enterprise

Open the project file and remove all references with Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0....打开项目文件并使用 Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0...删除所有引用。

Open web.config and remove all system.codedom compilers attributes打开 web.config 并删除所有 system.codedom 编译器属性

In my case, similar to Basim, there was a NuGet package that was telling the compiler we needed C# 6, which we didn't.在我的例子中,类似于 Basim,有一个 NuGet 包告诉编译器我们需要 C# 6,而我们不需要。

We had to remove the NuGet package Microsoft.CodeDom.Providers.DotNetCompilerPlatform which then removed:我们必须删除 NuGet 包Microsoft.CodeDom.Providers.DotNetCompilerPlatform然后删除:

  1. <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" /> from the packages.config file <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" />来自 packages.config 文件
  2. <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>

In the system.codedom node, you can see why it was bringing in roslyn: compilerOptions="/langversion:6system.codedom节点中,您可以看到它为什么引入 roslyn: compilerOptions="/langversion:6

Delete the Bin folder in your solution explorer and Build the solution again.删除解决方案资源管理器中的 Bin 文件夹并再次构建解决方案。 That would solve the problem那将解决问题

I had the same problem when installing my application on the server when everything worked perfectly on localhost.当一切在本地主机上完美运行时,我在服务器上安装我的应用程序时遇到了同样的问题。

None of these solutions woorked, I always had the same error:这些解决方案都没有奏效,我总是遇到同样的错误:

Could not find a part of the path 'C:\inetpub\wwwroot\myApp\bin\roslyn\csc.exe'

I ended up doing this:我最终这样做了:

  • on my setup project, right clic, view > file system在我的设置项目上,右键单击,查看 > 文件系统
  • create a bin/roslyn folder创建一个bin/roslyn文件夹
  • select add > files and add all files from packages\Microsoft.Net.Compilers.1.3.2\tools选择添加 > 文件并从packages\Microsoft.Net.Compilers.1.3.2\tools添加所有文件

This solved my problem.这解决了我的问题。

I have webproject without csproj file and solutions mentiond here did not work for me.我有没有 csproj 文件的 webproject,这里提到的解决方案对我不起作用。

Changing target .NET framework, reinstalling packages ( Update-Package -reinstall ) and then building the project worked for me.更改目标 .NET 框架,重新安装包( Update-Package -reinstall )然后构建项目对我有用。 You can even change target framework back after this operation(make suere you reinstall nuget packages again after).您甚至可以在此操作后更改目标框架(让您在之后再次重新安装 nuget 包)。

Other than deleting the Bin diretory from all projects inside the solution, delete the obj folders too.除了从解决方案中的所有项目中删除 Bin 目录外,还要删除 obj 文件夹。

In the main solution diretory remove the folder .vs在主解决方案目录中删除文件夹 .vs

Worked for me when trying to bring an already done project into a blank solution created on git.在尝试将已经完成的项目带入在 git 上创建的空白解决方案中时为我工作。

I tried multiple top answers until the below steps worked (ASP.NET project targeting .NET Framework 4.6.2, Visual Studio 2019 on a system with crazy restrictive group policies, March 2021).在执行以下步骤之前,我尝试了多个最佳答案(ASP.NET 项目针对 .NET Framework 4.6.2,Visual Studio 2019 在具有疯狂限制组策略的系统上,2021 年 3 月)。

I needed to:我需要:

  • run VS as Admin管理员身份运行 VS

  • in package manager console run在包管理器控制台中运行

    Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -v 2.0.1
  • Clean & Rebuild Solution清洁和重建解决方案

Without running VS as Admin, group policies blocked ps1 scripts that Update-Package needed to run.如果不以管理员身份运行 VS,组策略会阻止更新包需要运行的 ps1 脚本。

PS. PS。 Before this worked, I tried numerous other answers (and ran git reset --hard after they failed).在此之前,我尝试了许多其他答案(并在失败后运行 git reset --hard )。 I do not know if any of them contributed to this eventually working.我不知道他们中的任何人是否为最终的工作做出了贡献。 I tried:我试过了:

对于那些在构建服务器(TFS 或 Bamboo)上编译时遇到这个问题的人,我可以通过从“/t:”msbuild 选项中删除“clean”选项来解决这个问题。

my solution is using Nuget to update below items to latest version: - Microsoft.Net.Compilers - Microsoft.CodeDom.Providers.DotNetCompilerPlatform Then rebuilt the project.我的解决方案是使用 Nuget 将以下项目更新到最新版本: - Microsoft.Net.Compilers - Microsoft.CodeDom.Providers.DotNetCompilerPlatform 然后重建项目。 Since my project is a website so no *.csproj file.由于我的项目是一个网站,所以没有 *.csproj 文件。 The error above appears when I tried to view a cshtml in browser.当我尝试在浏览器中查看 cshtml 时出现上述错误。

The error fixed after the two items above updated to latest version.上述两项更新到最新版本后,该错误已修复。 I am in VS2015 and windows7 SP1我在VS2015和windows7 SP1

In my case I had this issue when i was running two visual studio IDE simultaneously.就我而言,当我同时运行两个 Visual Studio IDE 时遇到了这个问题。 So the solution was to clean the project and close the other instance.所以解决方案是清理项目并关闭另一个实例。

Reboot Windows.重新启动 Windows。

This is the only solution that worked for me after trying rebuild, delete contents of bin and rebuild, restart Visual Studio.这是尝试重建、删除bin的内容并重建、重新启动 Visual Studio 后唯一对我有用的解决方案。

It's yet another example of how terrible C#/.NET build tools are.这是 C#/.NET 构建工具有多糟糕的又一个例子。

I think (after reading many of the answers), the overall conclusion is that the cause and solution of this problem heavily depends on the setup and project, so if one answer does not work, just try another.我认为(在阅读了许多答案之后),总体结论是这个问题的原因和解决方案在很大程度上取决于设置和项目,所以如果一个答案不起作用,请尝试另一个答案。 Try non-intrusive/destructive solutions, such as restarting Visual Studio, rebooting, rebuilding, etc., FIRST, before messing with NuGet packages or reinstalling development tools.在弄乱 NuGet 包或重新安装开发工具之前,首先尝试非侵入性/破坏性解决方案,例如重新启动 Visual Studio、重新启动、重建等。 Good luck!祝你好运!

(NOTE: Using Visual Studio 2019, and project file was originally created in Visual Studio 2015. Maybe this helps someone investigate the issue) (注意:使用 Visual Studio 2019,项目文件最初是在 Visual Studio 2015 中创建的。也许这有助于某人调查问题)

(EDIT: Could this be caused by not rebooting after installing/modifying the Visual Studio installation or updating Visual Studio when the installer prompts to reboot?) (编辑:这可能是由于安装/修改 Visual Studio 安装后未重新启动或在安装程序提示重新启动时更新 Visual Studio 造成的吗?)

I had this issue on the server I was deploying to, and determined that I did not need我在部署到的服务器上遇到了这个问题,并确定我不需要

Microsoft.CodeDom.Providers.DotNetCompilerPlatform Microsoft.CodeDom.Providers.DotNetCompilerPlatform

So, I uninstalled it via nuget, and removed the reference in the web config.所以,我通过 nuget 卸载了它,并删除了 web 配置中的引用。 No more issues.没有更多的问题。

I originally tried to added target node to the .proj file as mentioned in some of the other answers, but that just lead to another error where the msbuild could not copy the pagefile.sys which seemed from what I read to be a bug in the nuget package.我最初尝试将目标节点添加到 .proj 文件中,如其他一些答案中所述,但这只会导致另一个错误,即msbuild无法复制pagefile.sys ,这似乎是我读到的错误nuget 包。

The following solved this issue for me:以下为我解决了这个问题:

  • Updating to the latest version of Visual Studio 2017 (using the installer app)更新到最新版本的 Visual Studio 2017(使用安装程序应用)

  • Clean and rebuild the solution清理并重建解决方案

Add PropertyGroup to your .csproj file将 PropertyGroup 添加到您的 .csproj 文件

<PropertyGroup>
  <PostBuildEvent>
    if not exist "$(WebProjectOutputDir)\bin\Roslyn" md "$(WebProjectOutputDir)\bin\Roslyn"      
    start /MIN xcopy /s /y /R "$(OutDir)roslyn\*.*" "$(WebProjectOutputDir)\bin\Roslyn"
  </PostBuildEvent>
</PropertyGroup>

I had this error for Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.06 but also with 1.0.7 that worked for @PrisonerZERO.我对Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.06有此错误,但对 @PrisonerZERO 工作的1.0.7也有此错误。 However when Microsoft released 1.0.8 2017-10-18 it finally started working for me again and I did not have to downgrade.但是,当 Microsoft 发布1.0.8 2017-10-18 时,它终于再次开始为我工作,我不必降级。

https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/ https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/

On my case, i Noticed that the "build" folder was not present in "packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0" path.就我而言,我注意到“packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0”路径中不存在“build”文件夹。 And that was the reason why the roslyn folder was not beeing created.这就是没有创建 roslyn 文件夹的原因。

So the solution for me was:所以对我来说解决方案是:

  1. Clean solution清洁溶液
  2. Go to Nuget Package Manager转到 Nuget 包管理器
  3. Uninstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform卸载 Microsoft.CodeDom.Providers.DotNetCompilerPlatform
  4. Clean solution清洁溶液
  5. Install Microsoft.CodeDom.Providers.DotNetCompilerPlatform again from Nuget package manager.从 Nuget 包管理器再次安装 Microsoft.CodeDom.Providers.DotNetCompilerPlatform。
  6. Clean/Rebuild清理/重建

And there you go.你去吧。 None of the solution above worked for me .上面的解决方案都不适合我。 Hope this helps anyone希望这对任何人都有帮助

为了防止构建也将 Roslyn 文件复制到 bin 目录,您还必须注释掉位于 Web 应用程序项目顶部的这一行:

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

I ran into this problem after updating some packages through NuGet.通过 NuGet 更新一些包后,我遇到了这个问题。 A rebuild (instead of a normal build) has worked for me.重建(而不是正常的构建)对我有用。

I had the same problem after updating DotNetCompilerPlatform.更新 DotNetCompilerPlatform 后我遇到了同样的问题。 Solved by Restarting Visual Studio > Clean Project > Build Project.通过重新启动 Visual Studio > Clean Project > Build Project 解决。

FYI...供参考...

As of 8/31/2017 upgrading to Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.7 is works.截至 2017 年 8 月 31 日,升级到 Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.7 是可行的。

This can be done in the following easy way-:这可以通过以下简单的方式完成 -

  • Create a new project of similar type anywhere in your system.在系统的任何位置创建一个类似类型的新项目。 Build it and copy over the roslyn folder to your bin directory.构建它并将 roslyn 文件夹复制到您的 bin 目录。

A lot of these answers are referring to the Nuget packages and/or cleaning and reloading your project.很多这些答案是指 Nuget 包和/或清理和重新加载您的项目。

If you have WCF service references and invalid endpoints, you can also get this error message.如果您有 WCF 服务引用和无效终结点,您也会收到此错误消息。 Make sure your endpoints are correct and update the service configuration with the correct endpoint in the .config and when you configure the service reference from the GUI.确保您的端点正确,并在 .config 中使用正确的端点更新服务配置,并在您从 GUI 配置服务引用时更新服务配置。

服务参考配置 GUI 的图像

I had to change the WebAPI and MVC project files to not build views:我不得不将 WebAPI 和 MVC 项目文件更改为不构建视图:

<MvcBuildViews>false</MvcBuildViews>

This resolved my TFS 2015 Build server error with roslyn.这用 roslyn 解决了我的 TFS 2015 Build server 错误。 Still not sure why csc.exe was copied to \bin\csc.exe, yet the publish process was looking for \bin\Roslyn\csc.exe...couldn't find the transformation causing that discrepancy.仍然不确定为什么 csc.exe 被复制到 \bin\csc.exe,但发布过程正在寻找 \bin\Roslyn\csc.exe...找不到导致该差异的转换。

I experienced this error on a Jenkins build server running MSBuild, which outputs the build files to a separate folder location (_PublishedWebsites).我在运行 MSBuild 的 Jenkins 构建服务器上遇到此错误,该服务器将构建文件输出到单独的文件夹位置 (_PublishedWebsites)。 Exactly the same - the roslyn folder was not in the bin directory, and all the roslyn files were lumped in with the bin files.完全一样 - roslyn 文件夹不在 bin 目录中,所有 roslyn 文件都与 bin 文件混为一谈。

@igor-semin 's answer was the only thing that worked for me (as I am using the C# 6 language features, I cannot simply uninstall the nuget packages as per other answers), but as I am also running CodeAnalysis, I was getting another error on my deployment target server: @igor-semin 的答案是唯一对我有用的东西(因为我正在使用 C# 6 语言功能,我不能像其他答案一样简单地卸载 nuget 包),但由于我也在运行 CodeAnalysis,所以我得到了我的部署目标服务器上的另一个错误:

An attempt to override an existing mapping was detected for type Microsoft.CodeAnalysis.ICompilationUnitSyntax with name "", currently mapped to type Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax, to type Microsoft.CodeAnalysis.VisualBasic.Syntax.CompilationUnitSyntax.检测到名称为“”的类型 Microsoft.CodeAnalysis.ICompilationUnitSyntax 覆盖现有映射的尝试,当前映射到类型 Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax,以键入 Microsoft.CodeAnalysis.VisualBasic.Syntax.CompilationUnitSyntax。

The reason for this is that as the roslyn files are getting dumped into the main bin directory, when you run the xcopy to recreate them in the nested roslyn folder, you now have 2 copies of these files being compiled and there is a clash between them.原因是因为 roslyn 文件被转储到主 bin 目录中,当您运行 xcopy 以在嵌套的 roslyn 文件夹中重新创建它们时,您现在有 2 个这些文件的副本正在编译并且它们之间存在冲突. After much frustration I decided on a 'hack' fix - an additional post-build task to delete these files from the bin directory, removing the conflict.经过很多挫折后,我决定进行“黑客”修复 - 一个额外的构建后任务,从 bin 目录中删除这些文件,消除冲突。

The .csproj of my offending projects now looks like:我的违规项目的 .csproj 现在看起来像:

................... more here ...................... ......................更多在这里......................

 <PropertyGroup>
   <PostBuildEvent>
   if not exist "$(WebProjectOutputDir)\bin\Roslyn" md "$(WebProjectOutputDir)\bin\Roslyn"
   start /MIN xcopy /s /y /R "$(OutDir)roslyn\*.*" "$(WebProjectOutputDir)\bin\Roslyn"
 </PostBuildEvent>
</PropertyGroup>
<Target Name="DeleteDuplicateAnalysisFiles" AfterTargets="AfterBuild">
   <!-- Jenkins now has copies of the following files in both the bin directory and the 'bin\rosyln' directory. Delete from bin. -->
   <ItemGroup>
     <FilesToDelete Include="$(WebProjectOutputDir)\bin\Microsoft.CodeAnalysis*.dll" />
   </ItemGroup>
   <Delete Files="@(FilesToDelete)" />
</Target>

................... more here ...................... ......................更多在这里......................

I ran into this issue with the publishing pipeline (which produces a _PublishedWebsites directory), and used this as a Target in the project:我在发布管道(生成 _PublishedWebsites 目录)中遇到了这个问题,并将其用作项目中的目标:

<Target Name="CopyRoslynCompilerFilesToPublishedWebsitesDirectory" AfterTargets="AfterBuild" Condition="Exists('$(OutDir)\_PublishedWebsites\$(TargetName)')">
    <Copy SourceFiles="@(RoslyCompilerFiles)" DestinationFolder="$(OutDir)\_PublishedWebsites\$(TargetName)\bin\roslyn" ContinueOnError="true" SkipUnchangedFiles="true" />
</Target>

The downside is that there will be two copies of the Roslyn files in the output.缺点是输出中会有两个 Roslyn 文件的副本。

I had this error after renaming a solution and some included projects, and playing around with removing nuget packages.在重命名解决方案和一些包含的项目并尝试删除 nuget 包后,我遇到了这个错误。 I compared the new project with the last working project, and found the following lines were missing and needed to be added back in:我将新项目与上一个工作项目进行了比较,发现缺少以下几行,需要重新添加:

  <Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
  <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')" />
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

Doing so resolved the issue for me.这样做为我解决了这个问题。

In my situation, our team don't want to keep 'packages' folder, so we put all dlls in other directory like 'sharedlib'.在我的情况下,我们的团队不想保留“packages”文件夹,因此我们将所有 dll 放在其他目录中,例如“sharedlib”。

I used build event to solve this problem.我使用构建事件来解决这个问题。

if "$(ConfigurationName)" == "Release" (
goto :release
) else (
goto:exit
)

:release
if not exist $(TargetDir)\roslyn mkdir $(TargetDir)\roslyn

copy /Y "$(ProjectDir)..\..\Shared Lib\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\tools\Roslyn45\*" "$(TargetDir)\roslyn"
goto :exit

:exit

None of the other answers worked for me.其他答案都不适合我。 After doing a folder compare before/after vs my expected committed files, i discovered that GIT was ignoring a required folder.在与我预期的提交文件之前/之后进行文件夹比较后,我发现 GIT 忽略了所需的文件夹。 If you are tracking the compiler in a repository, make sure the BUILD folder is tracked.如果您在存储库中跟踪编译器,请确保跟踪 BUILD 文件夹。 If it's not, the compiler won't ever be built and will throw this exact error after publish.如果不是,编译器将永远不会被构建,并且会在发布后抛出这个确切的错误。 I added this line to my .gitignore file:我将此行添加到我的.gitignore文件中:

!**/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1/build/

and now it's deploying to other computers properly.现在它正在正确部署到其他计算机。

I had a project running in VS2019 and then i open(in VS2019) another project for the first time and i got the above issue.我有一个在 VS2019 中运行的项目,然后我第一次打开(在 VS2019 中)另一个项目,我遇到了上述问题。 what I did as follow:我做了如下操作:

  1. I close the running project,我关闭正在运行的项目,
  2. Clean and rebuild the new project清理并重建新项目

Only point no.只点号2 was not working for me. 2 对我不起作用。

Issue问题

Be aware that the NuGet PM breaks the Rosalyn behavior.请注意,NuGet PM 会破坏 Rosalyn 行为。 Click Tools > NuGet Package Manager > Manage NuGet Packages for Solution If an update Exists for Microsoft.CodeDom.Providers.DotNetCompilerPlatform , Microsoft.Net.Compilers , or Microsoft.Net.Compilers.netcore , update them and the Solution will break!单击Tools > NuGet Package Manager > Manage NuGet Packages for Solution的 NuGet 包 如果Microsoft.CodeDom.Providers.DotNetCompilerPlatformMicrosoft.Net.CompilersMicrosoft.Net.Compilers.netcore存在更新,请更新它们,解决方案将中断! This occurs because the ASP Sites templates are set to use specific versions at project creation.这是因为 ASP 站点模板设置为在项目创建时使用特定版本。 To See the problem, click Show All Files in the Solution Explorer.要查看问题,请单击解决方案资源管理器中的显示所有文件。

Fix使固定

At project creation the $(WebProjectOutputDir)\bin doesn't exist, therefore when Rosalyn is added as a dependency by NuGet it installs it properly.在项目创建时$(WebProjectOutputDir)\bin不存在,因此当 NuGet 将 Rosalyn 添加为依赖项时,它会正确安装它。 After Updating the Solution Packages, the $(WebProjectOutputDir)\bin directory looks like so:更新解决方案包后, $(WebProjectOutputDir)\bin目录如下所示:

$(WebProjectOutputDir)\bin\bin\rosalyn

The easiest fix is to Cut & Paste rosalyn to the proper location, and then delete the extra bin folder.最简单的解决方法是将 rosalyn 剪切并粘贴到正确的位置,然后删除多余的bin文件夹。 You can now Refresh the page and the site will load.您现在可以刷新页面,网站将加载。

The answer for this is different for Website project and Web application Project.对于网站项目和 Web 应用程序项目,答案是不同的。 The underlying issue is same that NuGet package is behaving differently on different machine.根本问题是 NuGet 包在不同机器上的行为不同。 It may be rights issue or some execution policy which stops it from copying to Bin folder As you know Roslyn is new compiler.可能是权限问题或某些执行策略阻止它复制到 Bin 文件夹 如您所知 Roslyn 是新编译器。 you should have it in Bin folder for these Projects Go to your website NuGet Packages check this Folder Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0 \code\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0 Do you see it ?您应该将它放在这些项目的 Bin 文件夹中转到您的网站 NuGet Packages 检查此文件夹 Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0 \code\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0 你看到了吗? Can you see code\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\tools\RoslynLatest in it Now as part of compiling this Folder should get copied to your website under bin like this.您能在其中看到 code\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\tools\RoslynLatest 现在作为编译此文件夹的一部分,应该像这样将这个文件夹复制到您的网站下。 \code\WebSite1\Bin\Roslyn some how that is not happening for you . \code\WebSite1\Bin\Roslyn 一些你没有发生的事情。 Try running Visual studio as Admin .尝试以 Admin 身份运行 Visual Studio。 Copy Roslyn folder manually.手动复制 Roslyn 文件夹。 Try uninstall and install of NuGet Package.尝试卸载并安装 NuGet 包。 Remember this package compile your folder and if its not there you cannot compile anything and so you cannot add anything too.记住这个包编译你的文件夹,如果它不在那里你不能编译任何东西,所以你也不能添加任何东西。 Try copying this package to offline version tools -> options-> nuget package Manager->Package source-> Microsoft Visual Studio Offline Packages C:\Program Files (x86)\Microsoft SDKs\NuGetPackages尝试将此包复制到离线版本工具 -> 选项-> nuget 包管理器-> 包源-> Microsoft Visual Studio Offline Packages C:\Program Files (x86)\Microsoft SDKs\NuGetPackages

安装 nudget 包:Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix/1.0.0

I was also facing same issue got resolve by running the below command in nuget console通过在 nuget 控制台中运行以下命令,我也面临同样的问题得到解决

Install-Package Microsoft.Net.Compilers -Version 3.3.1安装包 Microsoft.Net.Compilers -Version 3.3.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM