首页 文章

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

提问于
浏览
311

我正在尝试运行从TFS源代码控制中检索到的Asp.net MVC项目 . 我添加了所有程序集引用,我能够成功构建和编译,没有任何错误或警告 .

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

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

以下是错误页面的完整屏幕截图 .

经过几天的研究,我明白Roslyn是.Net编译器平台,提供了先进的编译功能 . 但是,我不明白为什么我的构建试图找到\ bin \ roslyn \ csc.exe,因为我没有配置任何与Roslyn相关的东西,也不打算在我的项目中使用Roslyn .

30 回答

  • 5

    NuGet Package Manager

    您需要安装Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix,特别为该错误创建

  • 11

    在尝试了所有没有雪茄的修复后,我通过在Visual Studios中更新这个Nuget包来修复它:

    Microsoft.CodeDom.Providers.DotNetCompilerPlatform

    我从1.0.0到2.0.0作为参考(错误不再显示)

  • 5

    默认VS2015模板的问题是编译器实际上没有复制到tfr \ bin \ roslyn \目录,而是复制到 \ 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>
    
  • 2

    清洁和重建对我有用!

    Edit: 评论者说清洁步骤没有必要 . 你可以重建 .

  • 0

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

    要解决此问题,请在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>
    

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

  • 1

    这是known issueMicrosoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.6 . 降级到1.0.5为我解决了这个问题 .

  • 11

    我有没有csproj文件的webproject,这里提到的解决方案对我不起作用 .

    更改目标.NET框架,重新安装软件包( Update-Package -reinstall )然后构建项目对我有用 . 您甚至可以在此操作之后更改目标框架(以后再次重新安装nuget包) .

  • 3

    在我的情况下,解决方案是重新安装/升级Nuget包:

    • Microsoft.Net.Compilers 1.1.1

    • Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.1

    然后我查看.csproj并确保包的路径是正确的(在我的情况下.. \ .. \ packages \ * . *)在顶部的标签 <ImportProject> 和底部的名称"EnsureNuGetPackageBuildImports"的 <Target> . 这是在MVC 5和.NET Framework 4.5.2上 .

    Short answer - run this in the Package Manager Console:

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

  • 3

    在我的情况下,我在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

    花了一些时间后,我正在使用一个使用 Microsoft.Net.Compilers 的内部开发组件 . 内部组件使用 Microsoft.Net.Compilers 的原因是为了克服这个问题(C#: throw invalid expression compilation)并以这种方式解决(How to use c#7 with Visual Studio 2015?) . 这导致,当我在主程序上安装了主管时, Microsoft.Net.Compilers 自动添加它自己 .

    Solution

    我的工作是,从我们的内部组件卸载以下(按照@malikKhalil回答)

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

    并选择了Jenkins中的C#7编译器而不是C#6并重建,这是为了确保一切正常并正确构建 .

    最后在我的主程序中,我试图更新我的内部组件 . 除了再次构建之外的一切 . 它没有任何问题或问题 .

  • 9

    这是一个更多的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目录中(不在文件夹中) . 该应用程序似乎工作 .

  • 8

    FYI ...

    截至8/31/2017升级到Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.7是有效的 .

  • 4

    我的解决方案是使用Nuget将以下项目更新到最新版本: - Microsoft.Net.Compilers - Microsoft.CodeDom.Providers.DotNetCompilerPlatform然后重建项目 . 由于我的项目是一个网站所以没有* .csproj文件 . 当我尝试在浏览器中查看cshtml时出现上述错误 .

    上述两个项目更新到最新版本后修复了错误 . 我在VS2015和windows7 SP1

  • 1

    您的构建试图找到 \bin\roslyn\csc.exe ,因为您的项目中已添加了以下包 . 只需查看您 packages.config 文件,您可以将它们都放在那里

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

    什么是Roslyn和谁在项目中添加它们(包):如果您使用.net Framework 4.5.2使用VS2015创建项目,您可能已经注意到项目模板默认使用Roslyn . 实际上,Roslyn是Microsoft的.NET语言的开源编译器之一 . 我们为什么要删除Roslyn:如果您的项目有Roslyn参考,并且您有兴趣部署它没有服务器,您将在网站上收到不需要的错误,因为许多托管服务提供商仍然没有升级他们的服务器,因此不支持Roslyn.To解决这个问题问题,您需要从项目模板中删除Roslyn编译器 .

    if you are not interested in using Roslyn, follow steps bellow to delete it

    1. 删除Nuget包,使用Nuget Package Console中的以下命令

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

    2. 执行此操作后,应自动更新web.config文件 . 如果不是,请在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>
    
  • 6

    在我的情况下,我只需要转到Visual Studio Solution Explorer(Web应用程序项目)中的bin目录并直接包含roslyn项目 . 通过右键单击该文件夹并选择“包括在项目中” . 并再次检查解决方案以触发构建过程 .

    默认情况下不包含roslyn文件夹 .

  • 1

    使用Import Project =“.. \ packages \ Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0打开项目文件和 remove 所有引用....

    打开web.config和 remove 所有system.codedom编译器属性

  • 7

    根据Daniel Neel的评论:

    版本1.0.3的Microsoft.CodeDom.Providers.DotNetCompilerPlatform Nuget包适用于我,但版本1.0.6导致此问题中的错误

    降级到1.0.3为我解决了这个问题 .

  • 328

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

  • 52

    更新DotNetCompilerPlatform后我遇到了同样的问题 . 通过重新启动Visual Studio>清理项目>构建项目解决 .

  • 164

    问题

    请注意,NuGet PM打破了Rosalyn的行为 . 单击 Tools > NuGet Package Manager > Manage NuGet Packages for Solution 如果 Microsoft.CodeDom.Providers.DotNetCompilerPlatformMicrosoft.Net.CompilersMicrosoft.Net.Compilers.netcore 存在更新,请更新它们,解决方案将中断!发生这种情况是因为ASP站点模板设置为在项目创建时使用特定版本 . 要查看问题,请单击解决方案资源管理器中的显示所有文件 .

    修复

    在项目创建时 $(WebProjectOutputDir)\bin 不存在,因此当NuGet将Rosalyn添加为依赖项时,它会正确安装它 . 更新解决方案包后, $(WebProjectOutputDir)\bin 目录如下所示:

    $(WebProjectOutputDir)\bin\bin\rosalyn

    最简单的解决方法是将rosalyn剪切并粘贴到正确的位置,然后删除额外的 bin 文件夹 . 您现在可以刷新页面并加载站点 .

  • 7

    删除解决方案资源管理器中的Bin文件夹并再次构建解决方案 . 那样可以解决问题

  • 2

    当在localhost上完美运行时,我在服务器上安装应用程序时遇到了同样的问题 .

    这些解决方案都没有,我总是有同样的错误:

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

    我最终这样做了:

    我的安装项目

    • ,右侧clic,视图>文件系统

    • 创建一个 bin/roslyn 文件夹

    • 选择添加>文件并添加 packages\Microsoft.Net.Compilers.1.3.2\tools 中的所有文件

    这解决了我的问题 .

  • 36

    我在运行项目时遇到了同样的问题 . 这是我遵循的步骤 .

    • 右键单击解决方案

    • 选择清洁解决方案

    • 清理成功后,再次构建项目

    • 再次运行项目

    这次我看不出同样的错误 . 这按预期工作

  • 0

    如果你要添加ASPNETCOMPILER来编译MVC中的Razor视图,比如在this StackOverflow question中,那么将PhysicalPath更改为Roslyn nuget包所在的位置(通常通过 $CscToolPath 变量指向):

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

    所以,Rob Cannon's answer基本上对我有用,但我不得不调整一些选项 . 具体来说,我必须删除目标上的条件,以及更改Include属性,因为在我们的构建服务器上构建项目时$ CscToolPath为空 . 奇怪的是,$ 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>
    
  • 5

    我通过NuGet更新了一些软件包后遇到了这个问题 . 重建(而不是正常构建)对我有用 .

  • 126

    我不得不将WebAPI和MVC项目文件更改为不构建视图:

    <MvcBuildViews>false</MvcBuildViews>
    

    这解决了我使用roslyn的TFS 2015 Build服务器错误 . 仍然不确定为什么csc.exe被复制到\ bin \ csc.exe,但是发布过程正在寻找\ bin \ Roslyn \ csc.exe ...找不到导致这种差异的转换 .

  • 8

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

    除了从解决方案内的所有项目中删除Bin diretory之外,还要删除obj文件夹 .

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

    在尝试将已经完成的项目带入在git上创建的空白解决方案时,为我工作 .

  • 1

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

  • 1

    在我的例子中,类似于Basim,有一个NuGet包告诉编译器我们需要C#6,但我们没有 .

    我们不得不删除随后删除的NuGet包 Microsoft.CodeDom.Providers.DotNetCompilerPlatform

    packages.config文件中的

    • <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" />

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

    system.codedom 节点中,您可以看到它为什么引入了roslyn: compilerOptions="/langversion:6

相关问题