我正在尝试运行ASP。NET MVC(模型-视图-控制器)项目从TFS (Team Foundation Server)源代码控制检索。我已经添加了所有程序集引用,我能够成功地构建和编译,没有任何错误或警告。

但是我在浏览器中得到以下错误:

找不到路径的一部分 “C: \ B8akWorkspace \ B8akProject \ B8akSolution \ B8AK.Portal \ bin \ roslyn \ csc.exe”。

以下是错误页面的完整截图。

经过几天的研究,我了解到Roslyn是一个提供高级编译特性的. net编译器平台。但是,我不明白为什么我的构建试图找到\bin\roslyn\csc.exe,因为我没有配置任何与roslyn相关的东西。我也没打算让罗斯林参与我的项目。


当前回答

我尝试了多个顶级答案,直到下面的步骤起作用(ASP。NET项目,目标是。NET Framework 4.6.2, Visual Studio 2019,在一个具有疯狂限制性组策略的系统上,2021年3月)。

我需要:

以管理员身份运行VS 在包管理器控制台运行 更新- package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -v 2.0.1 清洁和重建解决方案

如果不以Admin身份运行VS,组策略会阻塞Update-Package需要运行的ps1脚本。

PS.在此工作之前,我尝试了许多其他答案(并在他们失败后运行git reset)。我不知道他们中是否有人最终促成了这一切。我试着:

https://stackoverflow.com/a/32780433/4658148 https://stackoverflow.com/a/34391473/4658148 https://stackoverflow.com/a/41484473/4658148 https://stackoverflow.com/a/62136000/4658148 https://stackoverflow.com/a/54341249/4658148 https://stackoverflow.com/a/51308385/4658148

其他回答

我在运行项目时也遇到了同样的问题。以下是我所遵循的步骤。

右击溶液 选择清洁溶液 清理成功后,再次构建您的项目 再次运行项目

这次我没有看到同样的错误。这与预期的一样。

我在Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.06上有这个错误,但在@ prisoner erzero上也有1.0.7的错误。然而,当微软发布1.0.8 2017-10-18时,它终于开始为我工作了,我不必降级。

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

这里有一个更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>

但是我注意到roslyn文件也在我的bin目录中(而不是在文件夹中)。不过,这款应用似乎还能用。

您的构建正在试图找到\bin\roslyn\csc.exe,因为以下包已添加到您的项目中。检查一下你的套餐。配置文件,你可以把它们都放在那里

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. Actually, Roslyn is one of open-source compilers for .NET languages from Microsoft. 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. To resolve this issue, you will need to remove the Roslyn compiler from the project template.

如果你不想利用罗斯林 按照下面的步骤删除它

1. 删除NuGet包,从NuGet包控制台使用以下命令

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

2. 在你完成这些之后,你的网。配置文件应该自动更新。如果不是,请在web中查找下面的代码。配置文件,如果找到,删除这段代码。

<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>

我有一个项目在VS2019中运行,然后我第一次打开(在VS2019中)另一个项目,我得到了上述问题。我所做的如下:

我关闭正在运行的项目, 清理并重新构建新项目

只有一点没有。2号不适合我。