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

C#asp.net.Netasp.net MvcRoslyn

C# Problem Overview


I am trying to run Asp.net MVC project retrieved from TFS 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 .Net compiler platform that offers advance 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 I intend to use Roslyn in my project.

C# Solutions


Solution 1 - C#

TL; DR

run this in the Package Manager Console:

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

More information

This problem is not related to Visual Studio itself, so answers suggesting adding build steps to copy files over are rather a workaround. Same with adding compiler binaries manually to the project.

The Roslyn compiler comes from a NuGet package and there is/was a bug in some versions of that package (I don't know exactly which ones). The solution is to reinstall/upgrade that package to a bug-free version. Originally before I wrote the answer back in 2015 I fixed it by installing following packages at specific versions:

  • Microsoft.Net.Compilers 1.1.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. This is on MVC 5 and .NET Framework 4.5.2.

Solution 2 - C#

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>

Solution 3 - C#

A clean and rebuild worked for me!

Solution 4 - C#

Your build is trying to find \bin\roslyn\csc.exe because the following packages have been added to your project. Just review your packages.config file, you can have both of them there

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

> What is Roslyn and Who added them(packages) in the project : If you’re using .net Framework 4.5.2 to create projects > using VS2015, you might have noticed that the project templates use > Roslyn by default. Actually, Roslyn is one of open-source > compilers for .NET languages from Microsoft. > > Why should we delete Roslyn : > If your project has Roslyn references and you are interested to deploy > it on server, you will get unwanted errors on the website as many > hosting providers still have not upgraded their servers and hence do > not support Roslyn. To resolve this issue, you will need to remove the > Roslyn compiler from the project template.

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

1. Remove NuGet packages, use the following commands from Nuget Package Console

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

2. After you do this, your web.config file should be auto-updated. In case it is not, look for the below code in web.config file and if it is found, delete this piece of code.

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

Solution 5 - C#

Here is a more MSBuild way of doing this.

<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). The app seems to work, though.

Solution 6 - C#

Too late for an answer but still posting incase it helps anyone.
Following the below steps fixed the error for me:

  1. delete packages folder
  2. open VS
  3. rebuild
  4. observe that NuGet packages are restored, but bin\roslyn isnt created
  5. unload project
  6. reload project
  7. rebuild
  8. observe that the bin\roslyn has been created now.

Solution 7 - C#

As noted in an issue in the Roslyn project on GitHub, a solution (that worked for me) is to simply unload and reload the project in Visual Studio.

The "bin\roslyn" folder wasn't created on build or rebuild until I reloaded the project.

Solution 8 - C#

I followed these steps and it worked perfectly

  • Delete all the bin and obj folders
  • Clean solution and rebuild
  • Run this command in powershell

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

Solution 9 - C#

0. The quick fix

As already noted in the currently highest voted answer, the quick fix is to use the package manager, Tools > Nuget Package Manager > Package Manager Console, to run

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

Packet Manager Console - how to open

"Packet Manager Console - how to open"

1. Code to reproduce the error

Here is code that reproduces the error:
https://user.it.uu.se/%7Ehesc0353/SrvrErr-reproduce.zip
(Originally from https://github.com/aspnet/AspNetDocs/tree/master/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client/sample/server/ProductsApp)

Consider trying the example code provided in the zip file above.
If no changes are made, Ctrl+F5 will reproduce the error.

Server Error '/' in Application

"Server Error '/' in Application"

2. A more robust solution

An alternative solution is to remove an attribute from the project's Web.config file.
(Web.config is in the same directory as the .csproj file.)
This will automatically and silently recreate your packages if they are missing.

Open the Web.config file in a text editor or in Visual Studio.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings></appSettings>
  ...
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /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.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
</configuration>

In the tag configuration > system.codedom > compilers > compiler language="c#;cs;csharp", completely remove the type attribute. – In short, remove the line that starts with type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, . 1

Visual Studio will take care of the rest. – No more Server Error in '/' Application.

3. HTTP Error 403

In the example provided above, hitting Ctrl+F5 will now result in an HTTP Error 403.

HTTP Error 403.14 - Forbidden

"HTTP Error 403.14 - Forbidden"

Try replacing http://localhost:64195 in your web browser with http://localhost:64195/api/products. The web API now displays correctly:

A web API containing products

"A web API containing products"


As a provocation, I tried removing the whole package directory from the Visual Studio project.
It was automatically and silently recreated as soon as the project was rebuilt.

References

1 Presumably, the same fix works for Visual Basic as well as for C#, but I haven't tried it.

Solution 10 - C#

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 didn't see the same error. This works as expected.

Solution 11 - C#

After trying all of the fixes with no cigar I fixed it by updating this Nuget Package in Visual Studios:

Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Mine was from 1.0.0 to 2.0.0 for reference (The error no longer shows)

Solution 12 - C#

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

Solution 13 - C#

For VS 2019 remove the following node completely:

<system.codedom>
</system.codedom>

Solution 14 - C#

NuGet Package Manager

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

Solution 15 - C#

In my case, before trying any of the other solutions, I switched to a "Release" configuration, rebuilt (the folder got created) and then switched back to "Debug", while the folder remained intact.

This was a checkout from source control of an older solution and apparently the original (automatic) package restore and building the project didn't create that folder in the bin directory.

Note that at time of writing this, the blamed component has reached v.2.

Solution 16 - C#

  • 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

Solution 17 - C#

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

Solution 18 - C#

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>

Solution 19 - C#

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

Solution 20 - C#

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 (https://stackoverflow.com/questions/47156277/c-throw-invalid-expression-compilation) and was solved this way (https://stackoverflow.com/questions/39461407/how-to-use-c7-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.

Solution 21 - C#

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.

Solution 22 - C#

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.

Solution 23 - C#

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

Solution 24 - C#

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)" />

Solution 25 - C#

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

Solution 26 - C#

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

Solution 27 - C#

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

Solution 28 - C#

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

Solution 29 - C#

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

Solution 30 - C#

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.

Solution 31 - C#

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

Changing target .NET framework, reinstalling packages (Update-Package -reinstall) and then building the project worked for me. You can even change target framework back after this operation(make suere you reinstall nuget packages again after).

Solution 32 - C#

Other than deleting the Bin diretory from all projects inside the solution, delete the obj folders too.

In the main solution diretory remove the folder .vs

Worked for me when trying to bring an already done project into a blank solution created on git.

Solution 33 - C#

I tried multiple top answers until the below steps worked (ASP.NET project targeting .NET Framework 4.6.2, Visual Studio 2019 on a system with crazy restrictive group policies, March 2021).

I needed to:

  • run VS as Admin

  • in package manager console run

    Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -v 2.0.1
    
  • Clean & Rebuild Solution

Without running VS as Admin, group policies blocked ps1 scripts that Update-Package needed to run.

PS. Before this worked, I tried numerous other answers (and ran git reset --hard after they failed). I do not know if any of them contributed to this eventually working. I tried:

Solution 34 - C#

For those struggling through this when compiling on the build server (TFS or Bamboo), I was able to solve this by removing the "clean" option from the "/t:" msbuild options.

Solution 35 - C#

my solution is using Nuget to update below items to latest version:

  • Microsoft.Net.Compilers
  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform Then rebuilt the project. Since my project is a website so no *.csproj file. The error above appears when I tried to view a cshtml in browser.

The error fixed after the two items above updated to latest version. I am in VS2015 and windows7 SP1

Solution 36 - C#

In my case I had this issue when i was running two visual studio IDE simultaneously. So the solution was to clean the project and close the other instance.

Solution 37 - C#

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

Solution 38 - C#

I had this issue on the server I was deploying to, and determined that I did not need

> Microsoft.CodeDom.Providers.DotNetCompilerPlatform

So, I uninstalled it via nuget, and removed the reference in the web config. No more issues.

I originally tried to added target node to the .proj file as mentioned in some of the other answers, but that just lead to another error where the msbuild could not copy the pagefile.sys which seemed from what I read to be a bug in the nuget package.

Solution 39 - C#

The following solved this issue for me:

  • Updating to the latest version of Visual Studio 2017 (using the installer app)

  • Clean and rebuild the solution

Solution 40 - C#

Add PropertyGroup to your .csproj file

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

Solution 41 - C#

I had this error for Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.06 but also with 1.0.7 that worked for @PrisonerZERO. However when Microsoft released 1.0.8 2017-10-18 it finally started working for me again and I did not have to downgrade.

https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/

Solution 42 - C#

On my case, i Noticed that the "build" folder was not present in "packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0" path. And that was the reason why the roslyn folder was not beeing created.

So the solution for me was:

  1. Clean solution
  2. Go to Nuget Package Manager
  3. Uninstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform
  4. Clean solution
  5. Install Microsoft.CodeDom.Providers.DotNetCompilerPlatform again from Nuget package manager.
  6. Clean/Rebuild

And there you go. None of the solution above worked for me . Hope this helps anyone

Solution 43 - C#

To prevent the build from also copying the Roslyn files to the bin directory, you have to also comment out this line that gets placed at the top of your Web application project:

<!--  <Import Project="..\..\..\DAS\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\..\..\DAS\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" /> -->

Solution 44 - C#

I ran into this problem after updating some packages through NuGet. A rebuild (instead of a normal build) has worked for me.

Solution 45 - C#

I had the same problem after updating DotNetCompilerPlatform. Solved by Restarting Visual Studio > Clean Project > Build Project.

Solution 46 - C#

FYI...

As of 8/31/2017 upgrading to Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.7 is works.

Solution 47 - C#

This can be done in the following easy way-:

  • Create a new project of similar type anywhere in your system. Build it and copy over the roslyn folder to your bin directory.

Solution 48 - C#

A lot of these answers are referring to the Nuget packages and/or cleaning and reloading your project.

If you have WCF service references and invalid endpoints, you can also get this error message. Make sure your endpoints are correct and update the service configuration with the correct endpoint in the .config and when you configure the service reference from the GUI.

Image of Service Reference Configuration GUI

Solution 49 - C#

I had to change the WebAPI and MVC project files to not build views:

<MvcBuildViews>false</MvcBuildViews>

This resolved my TFS 2015 Build server error with roslyn. Still not sure why csc.exe was copied to \bin\csc.exe, yet the publish process was looking for \bin\Roslyn\csc.exe...couldn't find the transformation causing that discrepancy.

Solution 50 - C#

I experienced this error on a Jenkins build server running MSBuild, which outputs the build files to a separate folder location (_PublishedWebsites). Exactly the same - the roslyn folder was not in the bin directory, and all the roslyn files were lumped in with the bin files.

@igor-semin 's answer was the only thing that worked for me (as I am using the C# 6 language features, I cannot simply uninstall the nuget packages as per other answers), but as I am also running CodeAnalysis, I was getting another error on my deployment target server:

An attempt to override an existing mapping was detected for type Microsoft.CodeAnalysis.ICompilationUnitSyntax with name "", currently mapped to type Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax, to type Microsoft.CodeAnalysis.VisualBasic.Syntax.CompilationUnitSyntax.

The reason for this is that as the roslyn files are getting dumped into the main bin directory, when you run the xcopy to recreate them in the nested roslyn folder, you now have 2 copies of these files being compiled and there is a clash between them. After much frustration I decided on a 'hack' fix - an additional post-build task to delete these files from the bin directory, removing the conflict.

The .csproj of my offending projects now looks like:

................... more here ......................

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

................... more here ......................

Solution 51 - C#

I ran into this issue with the publishing pipeline (which produces a _PublishedWebsites directory), and used this as a Target in the project:

<Target Name="CopyRoslynCompilerFilesToPublishedWebsitesDirectory" AfterTargets="AfterBuild" Condition="Exists('$(OutDir)\_PublishedWebsites\$(TargetName)')">
    <Copy SourceFiles="@(RoslyCompilerFiles)" DestinationFolder="$(OutDir)\_PublishedWebsites\$(TargetName)\bin\roslyn" ContinueOnError="true" SkipUnchangedFiles="true" />
</Target>

The downside is that there will be two copies of the Roslyn files in the output.

Solution 52 - C#

I had this error after renaming a solution and some included projects, and playing around with removing nuget packages. I compared the new project with the last working project, and found the following lines were missing and needed to be added back in:

  <Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
  <Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

Doing so resolved the issue for me.

Solution 53 - C#

In my situation, our team don't want to keep 'packages' folder, so we put all dlls in other directory like 'sharedlib'.

I used build event to solve this problem.

if "$(ConfigurationName)" == "Release" (
goto :release
) else (
goto:exit
)

:release
if not exist $(TargetDir)\roslyn mkdir $(TargetDir)\roslyn

copy /Y "$(ProjectDir)..\..\Shared Lib\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\tools\Roslyn45\*" "$(TargetDir)\roslyn"
goto :exit

:exit

Solution 54 - C#

None of the other answers worked for me. After doing a folder compare before/after vs my expected committed files, i discovered that GIT was ignoring a required folder. If you are tracking the compiler in a repository, make sure the BUILD folder is tracked. If it's not, the compiler won't ever be built and will throw this exact error after publish. I added this line to my .gitignore file:

!**/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1/build/

and now it's deploying to other computers properly.

Solution 55 - C#

Issue

Be aware that the NuGet PM breaks the Rosalyn behavior. Click Tools > NuGet Package Manager > Manage NuGet Packages for Solution If an update Exists for Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Microsoft.Net.Compilers, or Microsoft.Net.Compilers.netcore, update them and the Solution will break! This occurs because the ASP Sites templates are set to use specific versions at project creation. To See the problem, click Show All Files in the Solution Explorer.

Fix

At project creation the $(WebProjectOutputDir)\bin doesn't exist, therefore when Rosalyn is added as a dependency by NuGet it installs it properly. After Updating the Solution Packages, the $(WebProjectOutputDir)\bin directory looks like so:

$(WebProjectOutputDir)\bin\bin\rosalyn

The easiest fix is to Cut & Paste rosalyn to the proper location, and then delete the extra bin folder. You can now Refresh the page and the site will load.

Solution 56 - C#

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

Solution 57 - C#

Install nudget package: Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix/1.0.0

Solution 58 - C#

I was also facing same issue got resolve by running the below command in nuget console

Install-Package Microsoft.Net.Compilers -Version 3.3.1

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEyadView Question on Stackoverflow
Solution 1 - C#andy250View Answer on Stackoverflow
Solution 2 - C#MitchellView Answer on Stackoverflow
Solution 3 - C#pipedreambombView Answer on Stackoverflow
Solution 4 - C#Malik KhalilView Answer on Stackoverflow
Solution 5 - C#Rob CannonView Answer on Stackoverflow
Solution 6 - C#Sunil JohnsonView Answer on Stackoverflow
Solution 7 - C#Christian DavénView Answer on Stackoverflow
Solution 8 - C#Masoud DarvishianView Answer on Stackoverflow
Solution 9 - C#HenkeView Answer on Stackoverflow
Solution 10 - C#NarendraView Answer on Stackoverflow
Solution 11 - C#josh.thomsonView Answer on Stackoverflow
Solution 12 - C#nischaView Answer on Stackoverflow
Solution 13 - C#Shadi NamroutiView Answer on Stackoverflow
Solution 14 - C#Adrian BercaView Answer on Stackoverflow
Solution 15 - C#G. StoynevView Answer on Stackoverflow
Solution 16 - C#BojanView Answer on Stackoverflow
Solution 17 - C#hichamkazanView Answer on Stackoverflow
Solution 18 - C#jonnybotView Answer on Stackoverflow
Solution 19 - C#jrummellView Answer on Stackoverflow
Solution 20 - C#Maytham FahmiView Answer on Stackoverflow
Solution 21 - C#Jason CoyneView Answer on Stackoverflow
Solution 22 - C#Martijn van HalenView Answer on Stackoverflow
Solution 23 - C#BenView Answer on Stackoverflow
Solution 24 - C#Anrijs VītoliņšView Answer on Stackoverflow
Solution 25 - C#Juan MartíView Answer on Stackoverflow
Solution 26 - C#KorayemView Answer on Stackoverflow
Solution 27 - C#user6326076View Answer on Stackoverflow
Solution 28 - C#Mark C.View Answer on Stackoverflow
Solution 29 - C#user1903050View Answer on Stackoverflow
Solution 30 - C#Alexandre HamonView Answer on Stackoverflow
Solution 31 - C#Miroslav AdamecView Answer on Stackoverflow
Solution 32 - C#Erik SilvaView Answer on Stackoverflow
Solution 33 - C#Jacek KołodziejekView Answer on Stackoverflow
Solution 34 - C#AnthonyView Answer on Stackoverflow
Solution 35 - C#PennyView Answer on Stackoverflow
Solution 36 - C#Badr BellajView Answer on Stackoverflow
Solution 37 - C#Florian WinterView Answer on Stackoverflow
Solution 38 - C#PopoView Answer on Stackoverflow
Solution 39 - C#davrob01View Answer on Stackoverflow
Solution 40 - C#Igor SeminView Answer on Stackoverflow
Solution 41 - C#OgglasView Answer on Stackoverflow
Solution 42 - C#Felipe ThoméView Answer on Stackoverflow
Solution 43 - C#BasimView Answer on Stackoverflow
Solution 44 - C#HelenView Answer on Stackoverflow
Solution 45 - C#UhhaView Answer on Stackoverflow
Solution 46 - C#Prisoner ZEROView Answer on Stackoverflow
Solution 47 - C#Sriman Saswat SuvankarView Answer on Stackoverflow
Solution 48 - C#interesting-name-hereView Answer on Stackoverflow
Solution 49 - C#Robert J. GoodView Answer on Stackoverflow
Solution 50 - C#CiaranView Answer on Stackoverflow
Solution 51 - C#EKWView Answer on Stackoverflow
Solution 52 - C#TTTView Answer on Stackoverflow
Solution 53 - C#Ray ChungView Answer on Stackoverflow
Solution 54 - C#John LordView Answer on Stackoverflow
Solution 55 - C#eyoung100View Answer on Stackoverflow
Solution 56 - C#Jin ThakurView Answer on Stackoverflow
Solution 57 - C#mrKvaView Answer on Stackoverflow
Solution 58 - C#prashant pathakView Answer on Stackoverflow