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

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

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

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

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


当前回答

The answer for this is different for Website project and Web application Project. The underlying issue is same that NuGet package is behaving differently on different machine. It may be rights issue or some execution policy which stops it from copying to Bin folder As you know Roslyn is new compiler. 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 ? 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\WebSite1\Bin\Roslyn some how that is not happening for you . Try running Visual studio as Admin . Copy Roslyn folder manually. Try uninstall and install of NuGet Package. 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

其他回答

仅供参考……

截至2017年8月31日,升级到Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.7是有效的。

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

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

现在回答已经太晚了,但我仍然在发帖,希望能帮助到任何人。 以下步骤修复了我的错误:

删除包文件夹 开放和 重建 观察到NuGet包被恢复,但是bin\roslyn没有被创建 卸载项目 重新加载项目 重建 观察bin\roslyn现在已经创建。

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

默认的VS2015模板的问题是编译器实际上没有复制到{outdir}_PublishedWebsites\tfr\bin\roslyn\目录中,而是复制到{outdir}\roslyn\目录中。这可能与您的本地环境不同,因为AppHarbor使用输出目录构建应用程序,而不是“就地”构建解决方案。

要修复它,在xml块<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

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

参考:https://support.appharbor.com/discussions/problems/78633 -斜面-构建- aspnet - mvc项目生成——从vstudio - 2015企业