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

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

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

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

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


当前回答

您的构建正在试图找到\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>

其他回答

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

如果你正在添加ASPNETCOMPILER来编译MVC中的Razor视图,就像在这个StackOverflow问题中,然后改变PhysicalPath到Roslyn nuget包所在的地方(通常通过$CscToolPath变量指向):

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

除了从解决方案中的所有项目中删除Bin目录外,还需要删除obj文件夹。

在主解决方案目录中删除.vs文件夹

当我试图把一个已经完成的项目变成一个在git上创建的空白解决方案时,为我工作了。

在我的情况下,只要删除bin文件夹内的所有内容并重新编译就可以为我完成所有工作。

我在服务器上安装应用程序时遇到了同样的问题,而在localhost上一切都很完美。

这些解决方案都不奏效,我总是犯同样的错误:

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

我最后是这样做的:

在我的安装项目中,右clic,查看>文件系统 创建一个bin/roslyn文件夹 选择添加>文件,并添加包\Microsoft.Net.Compilers.1.3.2\tools中的所有文件

这解决了我的问题。