1018

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.

Henke
  • 1,466
  • 2
  • 9
  • 22
Eyad
  • 11,082
  • 5
  • 24
  • 41

55 Answers55

1511

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.

TylerH
  • 19,065
  • 49
  • 65
  • 86
andy250
  • 15,373
  • 2
  • 9
  • 20
532

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>
Mitchell
  • 6,114
  • 2
  • 14
  • 13
  • 12
    This does not resolve my issue. Now I get **'Could not find file 'C:\B8akWorkspace\B8akProject\B8akSolution\B8AK.Portal\bin\roslyn\csc.exe'**. Please notice that when I create a new MVC project in VS2015 I don't see the mentioned configuration in .csproj and it runs perfectly fine in the browser – Eyad Sep 25 '15 at 10:59
  • 4
    Thanks. I am now able to build and run the project in the browser after I downloaded the Roslyn directory and placing it in the /bin folder. I did not put the PstBuildEvent mentioned above and it still works. Maybe you want to edit your answer above and mention the need to manully placing the Roslyn files and to better reflect the solution. – Eyad Sep 25 '15 at 14:20
  • 2
    Well, in a normal situation; you should have the compiler inside your $(OutDir)roslyn\*.* folder, so this script will copy the compiler to the binfolder of your project. Apparently your installation of vs2015 did not include the compiler. – Mitchell Sep 25 '15 at 15:09
  • 1
    Hmm... Wouldn't the "start /min" mean that xcopy is running in a separate process while your build process continues merrily on its way creating a potential race condition? – Jason Duffett Dec 15 '15 at 16:20
  • 1
    Actually it is not a matter of VS. The compiler comes from a NuGet package - see my answer below. Adding the compiler binaries manually to the project is not the right solution I think. – andy250 Feb 10 '16 at 13:12
  • 2
    This should work without modifying the proj files. that's just fixing the symptom. doing a full rebuild should result in those files being there. – Simon Sabin Sep 14 '17 at 11:04
  • @Eyad Update MS dos.compiler in Nuget as well – Ali Jan 08 '18 at 04:59
  • I've used this to deploy in the AppHarbor also. Just make sure to include csc.exe and all *.dll in the packages folder of Microsoft.Net.Compilers package. I am using VS 2017 CE, ASP .NET MVC 5 targeting .NET 4.5.2 Framework just for reference. – Jerameel Resco Feb 10 '18 at 14:48
  • 15
    I found updating Microsoft.CodeDom.Providers.DotNetCompilerPlatform to 1.0.8 and Microsoft.Net.Compilers 2.6.1 helped me a lot. I didnt need to add this extra target. Looks like something similar was added in a later version of the tooling: https://github.com/aspnet/RoslynCodeDomProvider/commit/9408cd2aa2e394897564a0b8cd94b9350c0a3f89 – Ian Robertson Feb 13 '18 at 16:01
  • 1
    I dont know but adding this target does not copy roslyn folder. I am using VS 2017. – Jay Mar 15 '18 at 05:59
  • 6
    I have updated the version of Microsoft.Net.Compilers to version 2.10.0 from the Nuget and it has been the solution for me. I'm using targetFramework="4.6.2" – juanytuweb Nov 16 '18 at 12:39
  • suggest deleting obj and bin folder first before experimenting on newer the new ides. – RetroCoder Mar 29 '19 at 23:55
  • 2
    Don't add code to your solution just because VisualStudio is not behaving! Look at the other answers below. – demonicdaron Sep 19 '19 at 14:39
  • hmm.. similar to [this issue](https://stackoverflow.com/a/54972645/1042705) -- Nugets fix it – Irfan Jan 23 '20 at 06:04
  • Solved for me after removing `` from `web.config` – Zeeshan Ahmad Khalil Mar 30 '21 at 05:05
187

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 no 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>
Malik Khalil
  • 5,196
  • 1
  • 31
  • 30
  • I have deleted all but still getting that error any idea? – MonsterMMORPG Feb 18 '17 at 20:05
  • 30
    This isn't really a solution if you actually *want* to use the new compiler and the new features. – Matti Virkkunen Apr 11 '17 at 12:11
  • 16
    You're advocating against the future. – cchamberlain Apr 12 '17 at 00:56
  • This worked for me, but only after I replaced all usages of "nameof" and some other C# 6 features. I agree with @cchamberlain that it would be best to keep up, but I don't have much sway on which versions of the .NET framework are available on our web server. – phillihp Aug 24 '17 at 13:20
  • 2
    @cchamberlain why is it the future? I just think it should be straigthforward to use, but it looks many people are having troubles with it. – Alisson Dec 26 '17 at 02:09
  • 1
    @Alisson - Roslyn is the direction things are going in. It contains newer language features, is more performant, cross-platform, and open source. It came out after the other tools - hence future. Nothing says you need to use it, most upgrades incur some cost. See the "Why Roslyn compilation in ASP.NET?" section: https://blogs.msdn.microsoft.com/webdev/2014/05/12/enabling-the-net-compiler-platform-roslyn-in-asp-net-applications/ – cchamberlain Jan 03 '18 at 06:26
  • @cchamberlain I apologize if I expressed myself in a bad way, I just like to understand the benefits of things, rather than using just for the sake of it. If I understood correctly, if I used c# 7 features, I'd need Roslyn in order to build the project. Is that correct? – Alisson Jan 03 '18 at 10:06
  • @Alisson no worries, didn't take anything in a bad way. Difficult to say the exact feature set since it varies across versions of each compiler over time, but yes you will get new language features sooner on Roslyn. I've personally used it to get the ability to write c# 7 syntax in razor views. – cchamberlain Jan 03 '18 at 10:12
  • 1
    I only removed `` block from production web.config & my application starts running like a charm. – SarangK Feb 21 '19 at 03:59
  • 1
    if you want to publish MVC project to GoDaddy shared windows hosting, this is the answer. GoDaddy does not run executables like csc.exe – Jeson Martajaya Dec 12 '19 at 23:23
179

A clean and rebuild worked for me!

Community
  • 1
  • 1
pipedreambomb
  • 2,338
  • 1
  • 16
  • 16
  • 4
    I dont think the clean is required. According to this discussion of the issue a **rebuild** not a regular build will always put the roslyn file back. https://github.com/dotnet/roslyn/issues/15556 – leemicw Mar 28 '17 at 13:26
  • Rebuild resolved for me, I noticed this in the output `Copying file from "C:\Users\medmondson\Source\UK\Portal\Branches\v12\Source\packages\Microsoft.Net.Compilers.1.3.2\tools\csi.exe" to "bin\Debug\roslyn\csi.exe".` – m.edmondson Nov 17 '17 at 11:25
  • 5
    DotNetCompilerPlatform 1.0.3, Microsoft.Net.Compilers 1.3.2, VS Pro 2017 15.9.4 here. A clean/rebuild didn't work for me, even before and after restarting Visual Studio. Finally, a Build > Batch Build... > Rebuild All did the trick. It must have whispered just the right sweet-nothing to get VS to see it was missing the bin/roslyn directory in the output. – Johann Dec 14 '18 at 19:26
  • 2
    Clean and Rebuild did the trick for me. For those saying just doing rebuild will work...rebuild's behavior can be modified and does not always just do a clean and build. See #2 of [this answer](https://stackoverflow.com/a/1247480/4416750). – Lews Therin Apr 15 '19 at 17:18
  • @pipedreambomb, you're correct but you won't want to clean/rebuild all the time. – AGuyCalledGerald Jul 19 '19 at 11:52
  • I did a Rebuild at the solution level and fixed for me. Over time I've found a few nuget packages where the default build doesn't trigger some of their setup properly, but a Solution Rebuild does. – AaronLS May 21 '21 at 18:36
61

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.

Rob Cannon
  • 1,664
  • 3
  • 12
  • 14
  • 4
    You can put it anywhere in your .csproj file, at the same level as another tag. I usually put it toward the bottom. – Rob Cannon Jul 19 '16 at 15:21
44

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.

Christian Davén
  • 13,902
  • 10
  • 53
  • 68
41

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.
Sunil Johnson
  • 769
  • 6
  • 6
32

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

Masoud Darvishian
  • 3,080
  • 4
  • 27
  • 37
26

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.

TylerH
  • 19,065
  • 49
  • 65
  • 86
Narendra
  • 1,122
  • 1
  • 11
  • 16
23

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)

josh.thomson
  • 895
  • 8
  • 24
  • 1
    I did this too. Now the `roslyn` folder is created in my output path. I also see no "roslyn" reference in my csproj. It *could be* that `Target Name="CopyRoslyn...` is a VS2015 thing and not necessary in (the version of) 2017 I have. Worth to note: Since I updated DotnetCompilerPlatform *before* I played around with adding a copying target (the one I mentioned) I have a cleaner csproj. – LosManos Mar 25 '19 at 09:52
22
  1. Clean Solution
  2. Rebuild Solution ,These two steps worked for me.
nischa
  • 344
  • 2
  • 3
  • 1
    Works. I accidentally pressed `Ctrl C` when I was in the middle of checking out a branch in `git` and it screwed my repo up. `git reset --hard` didn't work, so I `git clean -xdf` and had to rebuild the project. However I ran into this error so I simply cleaned and rebuilt the project again and it worked for me. – Paul Carlton Jun 04 '19 at 21:46
  • This answer already existed for years before you posted it. – TylerH Jul 08 '20 at 21:16
16

As already noted by https://stackoverflow.com/questions/32780315#34391473, 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

But an alternative solution (which automatically and silently recreates your packages if they are missing) is to remove an attribute of your project's Web.config file.
(Web.config is in the same directory as your .csproj file.)

Open the Web.config file in a text editor (or inside Visual Studio).
- In the tag configuration > system.codedom > compilers > compiler language="c#;cs;csharp", completely remove the type attribute.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!-- ... -->
  <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 short, remove the line that starts with type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.

(Presumably, the same fix works for Visual Basic as well as for Csharp, but I have not tried it.)

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

In the example code I provided in the zip file above you will now get HTTP Error 403 when you hit Ctrl+F5.

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 as it should:

A web API containing products

As a provocation, I tried removing the whole package directory of my Visual Studio solution.
It was automatically and silently recreated as soon as I (re-)built it.


Last but not least, here is code that reproduces the error: http://schulze.000webhostapp.com/vs/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)

Server Error

TylerH
  • 19,065
  • 49
  • 65
  • 86
Henke
  • 1,466
  • 2
  • 9
  • 22
15

NuGet Package Manager

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

oatsoda
  • 1,863
  • 24
  • 45
Adrian Berca
  • 201
  • 3
  • 5
15

For VS 2019 remove the following node completely:

<system.codedom>
</system.codedom>
Shadi Namrouti
  • 7,498
  • 1
  • 38
  • 47
15

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.

G. Stoynev
  • 6,528
  • 6
  • 35
  • 49
  • I just had the same issue (again, in another project/dev machine) and remembered of my answer here. This solution worked again (VS2019, full framework, webapi project, Windows 10 Pro/IIS) – G. Stoynev Mar 09 '21 at 18:28
14
  • 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

Bojan
  • 385
  • 3
  • 10
11

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>
Community
  • 1
  • 1
jonnybot
  • 2,388
  • 1
  • 27
  • 55
  • 1
    The behavior is even worse. Locally, if you go to your _package_ folder and delete the two folders *Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.n.n* and build you code, then the $CscToolPath will be empty. If you build a second time, then it'll not be empty. The problem happens all the time on your build server, because it is always considered as a "first build". Your code works perfectly, but if you update the _Microsoft.Net.Compilers_ package, then you'll have to update the _.csproj_. Thank you. – Julien D. Sep 07 '16 at 12:53
  • 3
    Note that this solution will fail (or has to be adjusted) if the Microsoft.Net.Compilers's version changes. – JanDotNet Jan 04 '17 at 10:23
  • I upgraded the Microsoft.CodeDom.Providers.DotNetCompilerPlatform and then was able to proceed. – iowatiger08 Jan 26 '18 at 21:14
11

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

jrummell
  • 41,300
  • 17
  • 110
  • 165
10

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

hichamkazan
  • 168
  • 1
  • 7
9

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.

Jason Coyne
  • 6,179
  • 7
  • 35
  • 64
9

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.

maytham-ɯɐɥʇʎɐɯ
  • 21,551
  • 10
  • 85
  • 103
8

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.

8

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

TylerH
  • 19,065
  • 49
  • 65
  • 86
Ben
  • 537
  • 9
  • 8
7

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

TylerH
  • 19,065
  • 49
  • 65
  • 86
Juan Martí
  • 149
  • 2
  • 5
  • 2
    I think this is more simple and effective. Usually I get this error after cloning a project from a repository into a new computir. – David Ortega May 24 '19 at 14:29
  • After trying this, I got 403 Forbidden from IIS Express when running in the debugger. Restarting Visual Studio did not help, either, but rebooting Windows did. – Florian Winter Jul 01 '19 at 13:39
  • This repeats the [answer from user1903050](https://stackoverflow.com/a/41187980/2756409) from a few years prior. And the [answer from Masoud](https://stackoverflow.com/a/54341249/2756409) – TylerH Apr 28 '21 at 14:03
6

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

Korayem
  • 10,709
  • 5
  • 65
  • 52
  • 1
    The /d option copies only newer files (stands for "date"). Keep in mind deploying into cloud/azure where the time could be behind/in front of the local time. – Max Jul 18 '18 at 11:42
6

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

Community
  • 1
  • 1
6

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

user6326076
  • 61
  • 1
  • 1
5

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

Mark C.
  • 5,789
  • 4
  • 31
  • 60
  • 1
    All I had to do was uninstall the NuGet package "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" and that solved it for me (my project targets .NET 4.5.2). – BlueSky Apr 03 '16 at 16:15
  • 1
    This worked for me. You'll also want to remove Microsoft.Net.Compilers as there is no reason to keep this additional dependency around either. – Always Learning Apr 27 '16 at 17:24
5

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

user1903050
  • 51
  • 1
  • 1
5

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.

josemmo
  • 3,975
  • 3
  • 31
  • 43
Alexandre Hamon
  • 556
  • 6
  • 7
4

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

Miroslav Adamec
  • 852
  • 10
  • 19
  • This is a "website project". I used this command to just reinstall the one package: `update-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -reinstall` – GarDavis Jan 27 '19 at 20:19
4

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

Florian Winter
  • 3,381
  • 1
  • 33
  • 52
3

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

Penny
  • 476
  • 1
  • 4
  • 13
3

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.

Erik Silva
  • 31
  • 5
3

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.

Popo
  • 2,372
  • 5
  • 31
  • 53
  • 1
    Thanks for this. That worked for me. Just wondering if you know why DotNetCompilerPlatform was added in the first palce, what package usually adds this? – russelrillema Nov 06 '19 at 04:50
  • @russelrillema it is a default for MVC/WebAPI projects and I believe it is used for dynamic compilation. [Replacement CodeDOM providers that use the new .NET Compiler Platform ("Roslyn") compiler as a service APIs. This provides support for new language features in systems using CodeDOM (e.g. ASP.NET runtime compilation) as well as improving the compilation performance of these systems.](https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform) – Popo Nov 07 '19 at 15:40
3

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

davrob01
  • 341
  • 3
  • 5
2

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>
Igor Semin
  • 2,428
  • 1
  • 17
  • 19
2

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

Helen
  • 31
  • 3
2

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

Uhha
  • 31
  • 3
2

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/

Ogglas
  • 38,157
  • 20
  • 203
  • 266
2

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.

Badr Bellaj
  • 6,763
  • 1
  • 29
  • 30
1

FYI...

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

Prisoner ZERO
  • 12,996
  • 18
  • 80
  • 124
1

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

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

interesting-name-here
  • 1,647
  • 1
  • 17
  • 30
1

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:

0

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.

Robert J. Good
  • 1,087
  • 9
  • 8
0

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

Community
  • 1
  • 1
Ciaran
  • 473
  • 5
  • 14
0

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.

EKW
  • 124
  • 1
  • 9
0

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.

TTT
  • 7,472
  • 5
  • 41
  • 50
0

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

Jin Thakur
  • 2,265
  • 15
  • 12
0

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
Ray Chung
  • 11
  • 2
0

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.

John Lord
  • 1,261
  • 6
  • 21
-1

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')" /> -->
Basim
  • 209
  • 2
  • 5
-1

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.

eyoung100
  • 168
  • 9
-1

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

mrKva
  • 13
  • 3