programing tip

경로의 일부를 찾을 수 없습니다.… bin \ roslyn \ csc.exe

itbloger 2020. 10. 3. 10:06
반응형

경로의 일부를 찾을 수 없습니다.… bin \ roslyn \ csc.exe


TFS 소스 제어에서 검색 한 Asp.net MVC 프로젝트를 실행하려고합니다. 모든 어셈블리 참조를 추가했으며 오류나 경고없이 성공적으로 빌드하고 컴파일 할 수 있습니다.

하지만 브라우저에서 다음과 같은 오류가 발생합니다.

'C : \ B8akWorkspace \ B8akProject \ B8akSolution \ B8AK.Portal \ bin \ roslyn \ csc.exe'경로의 일부를 찾을 수 없습니다.

다음은 오류 페이지의 전체 스크린 샷입니다.

여기에 이미지 설명 입력

며칠간의 연구 끝에 Roslyn 이 고급 컴파일 기능을 제공하는 .Net 컴파일러 플랫폼이라는 것을 이해했습니다 . 그러나 Roslyn과 관련된 항목을 구성하지 않았거나 프로젝트에서 Roslyn을 사용하려고했기 때문에 빌드가 \ bin \ roslyn \ csc.exe를 찾는 이유를 이해할 수 없습니다.


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

제 경우 해결책은 Nuget 패키지를 다시 설치 / 업그레이드하는 것이 었습니다.

  • Microsoft.Net. 컴파일러 1.1.1
  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.1

그런 다음 .csproj를 살펴보고 <ImportProject>상단의 태그 내부 <Target>와 하단의 "EnsureNuGetPackageBuildImports"라는 이름 으로 패키지 경로가 올바른지 확인했습니다 (제 경우에는 .. \ .. \ packages \ *. *) . 이것은 MVC 5 및 .NET Framework 4.5.2에 있습니다.

짧은 대답-패키지 관리자 콘솔에서 실행하십시오.

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


\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을 지원하지 않기 때문에 웹 사이트에서 원치 않는 오류가 발생합니다. 문제가 발생하면 프로젝트 템플릿에서 Roslyn 컴파일러를 제거해야합니다.

Roslyn 사용에 관심이없는 경우 다음 단계 따라 삭제하십시오.

1. Nuget 패키지를 제거하고 Nuget 패키지 콘솔에서 다음 명령을 사용합니다.

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>

깨끗하고 재건이 나를 위해 일했습니다!


여기에 더 많은 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 디렉토리에도 있습니다. 그래도 앱이 작동하는 것 같습니다.


시가없이 모든 수정을 시도한 후 Visual Studio에서이 Nuget 패키지를 업데이트하여 수정했습니다.

Microsoft.CodeDom.Providers.DotNetCompilerPlatform

내 것은 참조를 위해 1.0.0에서 2.0.0까지였습니다 (오류가 더 이상 표시되지 않음)


이 단계를 따랐고 완벽하게 작동했습니다.

  • 모든 bin 및 obj 폴더 삭제
  • 솔루션 청소 및 재 구축
  • PowerShell에서이 명령 실행

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


GitHub의 Roslyn 프로젝트 문제에서 언급했듯이 솔루션 (저에게 효과적 이었습니다)은 Visual Studio에서 프로젝트를 간단히 언로드하고 다시로드하는 것입니다.

"bin \ roslyn"폴더는 프로젝트를 다시로드 할 때까지 빌드 또는 다시 빌드시 생성되지 않았습니다.


NuGet 패키지 관리자

You need to install Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix, was especially created for that error


  • Right click on your project and select Manage Nuget Packages
  • Find "Microsoft.CodeDom.Providers.DotNetCompilerPlatform"
  • Simply Update to an older or newer version (doesn't matter which), and then update again back to your original version.

This re-installs all the dependencies and files of the package (like csc.exe)

Nuget-DotNetCompilerPlatform


So, Rob Cannon's answer essentially worked for me, but I had to tweak a handful of the options. 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. Curiously, $CscToolPath was NOT empty when running locally.

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

  1. Clean Solution
  2. Rebuild Solution ,These two steps worked for me.

Updating nuget packages worked for me Right click on the solution > Manage NuGet packages for solution and update all the packages and specially: Microsoft.Net.Compilers and Microsoft.CodeDom.Providers.DotNetCompilerPlatform


This is a known issue with Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.6. Downgrading to 1.0.5 fixed this for me.


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


Per a comment by Daniel Neel above :

version 1.0.3 of the Microsoft.CodeDom.Providers.DotNetCompilerPlatform Nuget package works for me, but version 1.0.6 causes the error in this question

Downgrading to 1.0.3 resolved this issue for me.


In my case I have had issue in Jenkins when it tried to deploying it in Octopus with following error:

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

After spending some time, I was using an internal developed component that was using Microsoft.Net.Compilers. The reason the internal component was using Microsoft.Net.Compilers was to overcome this issue (C#: throw invalid expression compilation) and was solved this way (How to use C# 7 with Visual Studio 2015?). This result in, when I installed the component on the main program, the Microsoft.Net.Compilers get added it selves automatically.

Solution

My work around was, uninstall following from our internal component by (following @malikKhalil answer)

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

And chose C# 7 compiler in Jenkins instead of C# 6 and rebuild, this is to ensure everything is working and building correctly.

Than finally in my main program I tried to update my internal component. And everything than build again. It has built without any problems or issues.


Upgrading Microsoft.CodeDom.Providers.DotNetCompilerPlatform from 1.0.0 to 1.0.1 fixed this for me.


Open the project file and remove all references with Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0....

Open web.config and remove all system.codedom compilers attributes


If you were adding ASPNETCOMPILER to compile your Razor views in MVC, like in this StackOverflow question, then change PhysicalPath to place where Roslyn nuget package is located (usually pointed via $CscToolPath variable):

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


The problem with the default VS2015 templates is that the compiler isn't actually copied to the {outdir}_PublishedWebsites\tfr\bin\roslyn\ directory, but rather the {outdir}\roslyn\ directory. This is likely different from your local environment since AppHarbor builds apps using an output directory instead of building the solution "in-place".

To fix it, add the following towards end of .csproj file right after xml block <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">...</Target>

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

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


In my case by just Deleting everything inside the bin folder and recompiling did all the work for me.

Good luck to anyone having this problem.


In my case, similar to Basim, there was a NuGet package that was telling the compiler we needed C# 6, which we didn't.

We had to remove the NuGet package Microsoft.CodeDom.Providers.DotNetCompilerPlatform which then removed:

  1. <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" /> from the packages.config file
  2. <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>

In the system.codedom node, you can see why it was bringing in roslyn: compilerOptions="/langversion:6


I was also having same issue while running the project. here are the steps that i followed.

  1. Right click in solution
  2. select Clean solution
  3. After clean succeeded,Again build your project
  4. Run the project again

    This time i din't see the same error . This works as expected


Reboot Windows.

This is the only solution that worked for me after trying rebuild, delete contents of bin and rebuild, restart Visual Studio.

It's yet another example of how terrible C#/.NET build tools are.

I think (after reading many of the answers), the overall conclusion is that the cause and solution of this problem heavily depends on the setup and project, so if one answer does not work, just try another. Try non-intrusive/destructive solutions, such as restarting Visual Studio, rebooting, rebuilding, etc., FIRST, before messing with NuGet packages or reinstalling development tools. Good luck!

(NOTE: Using Visual Studio 2019, and project file was originally created in Visual Studio 2015. Maybe this helps someone investigate the issue)

(EDIT: Could this be caused by not rebooting after installing/modifying the Visual Studio installation or updating Visual Studio when the installer prompts to reboot?)


Delete the Bin folder in your solution explorer and Build the solution again. That would solve the problem


I had the same problem when installing my application on the server when everything worked perfectly on localhost.

None of these solutions woorked, I always had the same error:

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

I ended up doing this:

  • on my setup project, right clic, view > file system
  • create a bin/roslyn folder
  • select add > files and add all files from packages\Microsoft.Net.Compilers.1.3.2\tools

This solved my problem.


I have webproject without csproj file and solutions mentiond here did not work for me.

대상 .NET 프레임 워크 변경, 패키지 재설치 ( Update-Package -reinstall) 및 프로젝트 빌드가 저에게 효과적이었습니다. 이 작업 후에 대상 프레임 워크를 다시 변경할 수도 있습니다 (나중에 다시 nuget 패키지를 다시 설치해야 함).


솔루션 내의 모든 프로젝트에서 Bin 디렉토리를 삭제하는 것 외에 obj 폴더도 삭제하십시오.

기본 솔루션 디렉토리에서 .vs 폴더를 제거하십시오.

이미 완료된 프로젝트를 git에서 만든 빈 솔루션으로 가져 오려고 할 때 나를 위해 일했습니다.


.csproj 파일에 PropertyGroup 추가

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

참고 URL : https://stackoverflow.com/questions/32780315/could-not-find-a-part-of-the-path-bin-roslyn-csc-exe

반응형