Search code examples
c#asp.net.netvisual-studioroslyn

Could not find a part of the path ... bin\roslyn\csc.exe


I am trying to run an ASP.NET MVC (model-view-controller) project retrieved from TFS (Team Foundation Server) source control. 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'.

Here is a full screenshot of the error page.

enter image description here

After few days of research, I understood that Roslyn is a .NET compiler platform that offers advanced compiling features. 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 did I intend to use Roslyn in my project.


Solution

  • 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

    Add this code in your .csproj file:

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