roslyn compiler not copied to AspnetCompileMerge folder using msbuild

Related searches

I have a .NET MVC project that I'm trying to deploy using Jenkins.

I had been letting Jenkins run msbuild, then copying the resulting files out using RoboCopy. I wanted to switch to just use a publish profile. The publishing profile works fine on my local machine using Visual Studio, but on the Jenkins host it fails using msbuild.

The error it gives is

ASPNETCOMPILER : error ASPRUNTIME: Could not find a part of the path 'C:\Program Files (x86)\Jenkins\jobs\myProject\workspace\myProject\obj\Debug\AspnetCompileMerge\Source\bin\roslyn\csc.exe'. [C:\Program Files (x86)\Jenkins\jobs\myProject\workspace\myProject\calendar.csproj]

I'm using the Microsoft.Net.Compilers nuget package to pull in the C# compiler, because some of the collaborators on the project are still on Visual Studio 2013, but we're using C#6 language features in the project.

Thing is, the project built just fine using MSBuild on jenkins before I added the publish flag. It's only since adding the /p:DeployOnBuild=true;PublishProfile=MyProfile setting that it started failing... yet the publish step works fine from withing Visual Studio, and the roslyn compiler even gets copied to the obj\Debug\AspnetCompileMerge\Source\bin\ folder on my local machine. What gives?

Honestly, since msbuild14 is available on the Jenkins server, it probably doesn't even need the roslyn csc.exe file. Is there a way I can make msbuild ignore it?

My Publish Profile
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="">
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
What I've Tried So Far

I've tried updating the compiler package.

Manually copying compiler

I added steps to my .csproj file to force-copy the missing compiler files to the AspnetCompileMerge directory (I'd already been copying them to the bin\roslyn directory to resolve another problem)

<Target Name="CopyRoslynFiles" AfterTargets="BeforeBuild">
    <RoslynFiles Include="$(SolutionDir)packages\Microsoft.Net.Compilers.1.1.1\tools\*" Exclude="$(SolutionDir)packages\Microsoft.Net.Compilers.1.1.1\tools\*.sys" />
  <MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" />
  <MakeDir Directories="$(WebProjectOutputDir)\obj\$(Configuration)\AspnetCompileMerge\Source\bin\roslyn" />
  <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
  <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\obj\$(Configuration)\AspnetCompileMerge\Source\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
Turning off Updateability in the publish profile

Based on Wesley Rathburn's answer on a similar question, I tried making the precompiled site so it could not be updated in the publish profile:


Though this revealed some dead code that needed removed in my views, it didn't fix the error during the jenkins build.

Running MsBuild locally

I can successfully run the msbuild command on my local machine. It deploys to the server and everything. Here's the command I run in powershell:

&"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /p:Configuration=Debug "/p:DeployOnBuild=true;PublishProfile=MyProfile" myproject\myproject.csproj
Removing the statements that copy the compiler entirely

It occurred to me that maybe I didn't need the statements to copy the roslyn compiler to the bin folder anymore, since msbuild14 was available on Jenkins now (and I'm not sure it was when I first built the project). Sadly, same error occurs. It's looking for the roslyn\csc.exe file, even though there's no apparent need for it to do so!

Just putting this here, because I spent two days trying to resolve this same issue (roslyn csc.exe not copied), but none of these answers solved my problem.

It turns out that Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.6 (and 1.0.7) is broken. Downgrade to 1.0.5.

I was getting the same errors as everyone else here, but I'm using VS 2017, and both local WebDeploy as well as AzureDeploy were broken (no csc.exe found). I tried all the suggestions that I could find on the internet (most of them redirect back to this SO post) but nothing worked until I downgraded to 1.0.5.

So I hope this is helpful to anyone who is struggling and has just recently upgrade to 1.0.6!

See: and

Roslyn binaries not copied properly on publish in 1.0.6 � Issue #13 , NET app using Roslyn compiler for scripting purposes. AspNetCompileMerge\ Source\bin\roslyn\csc.exe dotnet/roslyn#21340 however i checked through MSBuild im using c#5 i thought this could be the answer. Seems to me every version after 1.0.5 does not copy roslyn into the bin folder even on a� roslyn compiler not copied to AspnetCompileMerge folder using msbuild; System.Web.Razor.dll not copied to bin folder; SQLite assembly not copied to output folder for unit testing; Roslyn VB.Net Specify Compiler Version; Wordpress not writting to folder using fwrite(); System.Net.Http DLL not copied into bin folder - IdentityServer4.AccessTokenValidation

So, the workaround I'm using for now (which I don't entirely like), is just to remove the dependencies on the Compilers and CodeDOM Compilers packages. I also had to clear out the references in the .csproj and web.config files. That involved removing those packages from a shared assembly as well.

This will break the project for people still using Visual Studio 2013, which I don't like, but it builds on my Jenkins host now, which I do like. If anyone has a better solution, I'd be happy to hear it.

Replace CodeDom with Roslyn but “bin\roslyn\csc.exe not found , Replace CodeDom with Roslyn but “bin\roslyn\csc.exe not found! CSharpCodeProvider with DotNetCompilerPlatform. of C# inside cshtml and codes, and that's why it looks for a bin folder. We don't know the exact absolute path of csc.exe so using env variables, app.config key or msbuild.exe is out of� I added steps to my .csproj file to force-copy the missing compiler files to the AspnetCompileMerge directory (I'd already been copying them to the bin\roslyn directory to resolve another problem) Recommend: c# - Dependent DLL is not getting copied to the build output folder in Visual Studio

So yeah, I have this problem too with VS2017 & VS2019 and Microsoft.CodeDom.Providers.DotNetCompilerPlatform2.0.1 too. Did a lot of troubleshoooting msbuild and digging deep and trying to do my own workarounds and the changes in build file that just did nothing, but that didn't seem right at all. So I started looking in a different direction.

What I discovered was I couldn't build a .csproj directly and have either the nuget targets in Microsoft.CodeDom.Providers.DotNetCompilerPlatform get run by msbuild, or my own custom ones.

However using msbuild with the .sln with a target of myproj:Rebuild made everything work.

bin\roslyn files locked during build, When building a web solution (not .net core). The bin folder is repeatedly locked due to the files in the roslyn folder being Build errors show the following: Unable to copy file "[project location]\packages\Microsoft.Net. by Leftyx Jul 29, 2017 at 11:01 AM taskkill /IM iisexpress.exe /F taskkill /im msbuild.exe /f /t taskkill /im� The project I'm trying to compile is a C# .Net Framework WebSite that has only a solution file and no project file. The web.config has the <system.codedom> sections needed to target the Roslyn compiler to take advantage of the C#6 syntax however because I'm not using Visual Studio to compile the application the needed files in the bin/roslyn

c#, i have .net mvc project i'm trying deploy using jenkins. i had been letting jenkins run msbuild, copying resulting files out using robocopy. wanted� Is there a workaround on this issue besides copying and pasting the roslyn folder into the bin, i have tried using the version 1.0.5 of the dom compiler and have also set csc.exe as environment variable, however i checked through MSBuild im using c#5 i thought this could be the answer.

CMS 11.3.2, CMS 11.3.2 - Could not find a part of the path 'bin\roslyn\csc.exe' /roslyn- compiler-not-copied-to-aspnetcompilemerge-folder-using-msbuild. I've just upgraded my product to work with .NET Standard tools and have noticed that the compiler isn't being output to to the build folder. I'm not sure if this is a seperate bug or not, if so then I'll open a new ticket. My target framework is net46.

I have an ASP.NET Web Application project which builds successfully. After updating Microsoft.CodeDom.Providers.DotNetCompilerPlatform from 1.0.5 to 1.0.6 it still builds, but when publishing I get the error: Transformed Web.config using

  • updating to 1.0.8 fixed the issue
  • I was hoping for something better but your workaround did work for me.
  • This isn't really an option if you are using C# 6 features in your Razor code. Has anybody found a different alternative?
  • I'm trying to understand IF I need this Roslyn compiler or not. I have a .NET WebAPI2 project and it seems to include it by default. However, my CI process (using BitBucket Pipelines) uses MONO and it throws this error: " Error building target IncludeRoslynCompilerFilesToItemGroup: Item has already been added. Key in dictionary: 'Link' Key being added: 'Link'" . I remove them and my API project works fine (I am using Angular2, NOT MVC)). I don't fully understand WHY I would need it or if this is a good move...
  • Simple version: The NuGet dependency I mention in my question (Microsoft.Net.Compilers) is used to allow people running Visual Studio 2013 to compile C# 6 code. If no one on your team is building on a Windows host that uses VS 2013, you probably won't need it. The new compiler is included in VS 2015 and later.
  • Have you ever found an actual solution to this? I don't want to be unable to not update my project.