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

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

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

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

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


当前回答

我在运行MSBuild的Jenkins构建服务器上遇到了这个错误,它将构建文件输出到一个单独的文件夹位置(_publhedwebsites)。完全一样- roslyn文件夹不在bin目录中,所有的roslyn文件都集中在bin文件中。

@igor-semin的回答对我来说是唯一有用的(因为我正在使用c# 6语言功能,我不能像其他答案一样简单地卸载nuget包),但由于我也在运行CodeAnalysis,我在部署目标服务器上得到了另一个错误:

检测到试图覆盖名称为“”的Microsoft.CodeAnalysis.ICompilationUnitSyntax类型的现有映射,当前映射为Microsoft.CodeAnalysis.CSharp.Syntax类型。CompilationUnitSyntax,输入Microsoft.CodeAnalysis.VisualBasic.Syntax.CompilationUnitSyntax。

这样做的原因是,当roslyn文件被转储到主bin目录中时,当您运行xcopy在嵌套的roslyn文件夹中重新创建它们时,您现在有两个正在编译的这些文件副本,并且它们之间存在冲突。在经历了很多挫折后,我决定进行一个“黑客”修复-一个额外的构建后任务,从bin目录中删除这些文件,消除冲突。

我的问题项目的.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>
<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>

...................更多信息请点击这里......................

其他回答

仅供参考……

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

默认的VS2015模板的问题是编译器实际上没有复制到tfr\bin\roslyn\目录中,而是复制到{outdir}\roslyn\目录中

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

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

我有webproject没有csproj文件和解决方案,这里提到的不适合我。

更改目标。net框架,重新安装包(Update-Package -重装),然后构建项目对我来说很有效。你甚至可以在这个操作之后更改目标框架(确保你重新安装了nuget包)。

默认的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企业