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

在尝试运行从TFS获取的Asp.net MVC项目时,遇到'找不到路径bin\roslyn\csc.exe'的错误。研究后发现Roslyn是.Net的编译器平台。问题可能涉及编译器位置、.csproj文件配置、Roslyn文件夹未包含在项目中或Nuget包需要更新。解决方案包括修改.csproj文件、直接包含Roslyn项目、重新安装/升级Nuget包或调整目标选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自:Could not find a part of the path … bin\roslyn\csc.exe

I am trying to run Asp.net MVC project retrieved from TFS source control. 我正在尝试运行从TFS源代码控制检索的Asp.net MVC项目。 I have added all assembly references and I am able to build and compile successfully without any error or warning. 我已经添加了所有程序集引用,并且能够成功构建和编译而没有任何错误或警告。

But I get the following error in the browser: 但是我在浏览器中收到以下错误:

Could not find a part of the path 'C:\\B8akWorkspace\\B8akProject\\B8akSolution\\B8AK.Portal\\bin\\roslyn\\csc.exe'. 找不到路径“ C:\\ B8akWorkspace \\ B8akProject \\ B8akSolution \\ B8AK.Portal \\ bin \\ roslyn \\ csc.exe”的一部分。

Here is a full screenshot of the error page. 这是错误页面的完整屏幕截图。

在此处输入图片说明

After few days of research, I understood that Roslyn is .Net compiler platform that offers advance compiling features. 经过几天的研究,我了解到Roslyn是.Net编译器平台,可提供高级编译功能。 However, I do not understand why my build is trying to find \\bin\\roslyn\\csc.exe because I did not configure anything related to Roslyn nor I intend to use Roslyn in my project. 但是,我不明白为什么我的版本试图查找\\ bin \\ roslyn \\ csc.exe,因为我没有配置与Roslyn相关的任何内容,也不打算在项目中使用Roslyn。


#1楼

参考:https://stackoom.com/question/2DXel/找不到路径的一部分-bin-roslyn-csc-exe


#2楼

The problem with the default VS2015 templates is that the compiler isn't actually copied to the tfr\\bin\\roslyn\\ directory, but rather the {outdir}\\roslyn\\ directory 默认VS2015模板的问题在于,编译器实际上并未复制到tfr \\ bin \\ roslyn \\目录,而是复制到{outdir} \\ roslyn \\目录

Add this code in your .csproj file: 将此代码添加到您的.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>

#3楼

Here is a more MSBuild way of doing this. 这是执行此操作的更多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>

But I notice that the roslyn files are also in my bin directory (not in a folder). 但是我注意到roslyn文件也位于我的bin目录中(而不是文件夹中)。 The app seems to work, though. 该应用程序似乎可以正常运行。


#4楼

In my case I just needed to go to the bin directory in Visual Studio Solution Explorer (web application project) and include the roslyn project directly. 就我而言,我只需要转到Visual Studio解决方案资源管理器(Web应用程序项目)中的bin目录,并直接包含roslyn项目。 By right clicking the folder and selecting Include In Project. 右键单击该文件夹,然后选择“包含在项目中”。 And check in the solution again to trigger the build process. 并再次签入解决方案以触发构建过程。

The roslyn folder was not included by default. 默认情况下不包括roslyn文件夹。


#5楼

In my case the solution was to re-install/upgrade Nuget packages: 在我的情况下,解决方案是重新安装/升级Nuget软件包:

  • Microsoft.Net.Compilers 1.1.1 Microsoft.Net。编译器1.1.1
  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.1 Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.1

Then I looked into .csproj and made sure that the paths to packages are correct (in my case ..\\..\\packages\\*.*) inside tags <ImportProject> on top and in <Target> with name "EnsureNuGetPackageBuildImports" on the bottom. 然后,我检查了.csproj并确保包的路径正确(在我的情况下是.. \\ .. \\ packages \\ *。*),位于顶部的<ImportProject>标签和位于<Target> ,名称为“ EnsureNuGetPackageBuildImports”的标签中底端。 This is on MVC 5 and .NET Framework 4.5.2. 这是在MVC 5和.NET Framework 4.5.2上。

Short answer - run this in the Package Manager Console: 简短答案-在Package Manager控制台中运行以下命令:

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


#6楼

So, Rob Cannon's answer essentially worked for me, but I had to tweak a handful of the options. 因此, 罗布·坎农(Rob Cannon)的答案基本上对我有用,但是我不得不调整一些选项。 Specifically, I had to remove the condition on the target, as well as change the Include attribute, as $CscToolPath was empty when the project was being built on our build server. 具体来说,我必须删除目标上的条件,并更改Include属性,因为在构建服务器上构建项目时,$ CscToolPath为空。 Curiously, $CscToolPath was NOT empty when running locally. 奇怪的是,$ 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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值