title: roslyn compiler not copied to AspnetCompileMerge folder using msbuild
body: <p>I have a .NET MVC project that I'm trying to deploy using Jenkins.</p>
  
  <p>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.</p>
  
  <p>The error it gives is</p>
  
  <blockquote>
    <p>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]</p>
  </blockquote>
  
  <p>I'm using the <a href="https://www.nuget.org/packages/Microsoft.Net.Compilers/" rel="nofollow noreferrer">Microsoft.Net.Compilers</a> 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.</p>
  
  <p>Thing is, the project built just fine using MSBuild on jenkins before I added the publish flag. It's only since adding the <code>/p:DeployOnBuild=true;PublishProfile=MyProfile</code> 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?</p>
  
  <p>Honestly, since msbuild14 is available on the Jenkins server, it probably doesn't even <em>need</em> the roslyn csc.exe file. Is there a way I can make msbuild ignore it?</p>
  
  <h1>My Publish Profile</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;PropertyGroup&gt;
      &lt;WebPublishMethod&gt;FileSystem&lt;/WebPublishMethod&gt;
      &lt;LastUsedBuildConfiguration&gt;Debug&lt;/LastUsedBuildConfiguration&gt;
      &lt;LastUsedPlatform&gt;Any CPU&lt;/LastUsedPlatform&gt;
      &lt;SiteUrlToLaunchAfterPublish /&gt;
      &lt;LaunchSiteAfterPublish&gt;True&lt;/LaunchSiteAfterPublish&gt;
      &lt;ExcludeApp_Data&gt;False&lt;/ExcludeApp_Data&gt;
      &lt;publishUrl&gt;\\myserver\someshare\mysite&lt;/publishUrl&gt;
      &lt;DeleteExistingFiles&gt;True&lt;/DeleteExistingFiles&gt;
      &lt;PrecompileBeforePublish&gt;True&lt;/PrecompileBeforePublish&gt;
      &lt;EnableUpdateable&gt;True&lt;/EnableUpdateable&gt;
      &lt;DebugSymbols&gt;False&lt;/DebugSymbols&gt;
      &lt;WDPMergeOption&gt;DonotMerge&lt;/WDPMergeOption&gt;
    &lt;/PropertyGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <h1>What I've Tried So Far</h1>
  
  <p>I've tried updating the compiler package.</p>
  
  <h2>Manually copying compiler</h2>
  
  <p>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 <a href="https://stackoverflow.com/a/34818907/1524502">resolve</a> <a href="https://stackoverflow.com/questions/32780315/could-not-find-a-part-of-the-path-bin-roslyn-csc-exe">another problem</a>)</p>
  
  <pre><code>&lt;Target Name="CopyRoslynFiles" AfterTargets="BeforeBuild"&gt;
    &lt;ItemGroup&gt;
      &lt;RoslynFiles Include="$(SolutionDir)packages\Microsoft.Net.Compilers.1.1.1\tools\*" Exclude="$(SolutionDir)packages\Microsoft.Net.Compilers.1.1.1\tools\*.sys" /&gt;
    &lt;/ItemGroup&gt;
    &lt;MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" /&gt;
    &lt;MakeDir Directories="$(WebProjectOutputDir)\obj\$(Configuration)\AspnetCompileMerge\Source\bin\roslyn" /&gt;
    &lt;Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" /&gt;
    &lt;Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\obj\$(Configuration)\AspnetCompileMerge\Source\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" /&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <h2>Turning off Updateability in the publish profile</h2>
  
  <p>Based on Wesley Rathburn's answer on <a href="https://social.msdn.microsoft.com/Forums/vstudio/en-US/442b100a-2b88-4ac4-b655-0c1345791f15/roslyn-cscexe-web-api-2-on-hosting-server?forum=msbuild" rel="nofollow noreferrer">a similar question</a>, I tried making the precompiled site so it could not be updated in the publish profile:</p>
  
  <pre><code>&lt;EnableUpdateable&gt;False&lt;/EnableUpdateable&gt;
  </code></pre>
  
  <p>Though this revealed some dead code that needed removed in my views, it didn't fix the error during the jenkins build.</p>
  
  <h2>Running MsBuild locally</h2>
  
  <p>I <em>can</em> successfully run the msbuild command on my local machine. It deploys to the server and everything. Here's the command I run in powershell:</p>
  
  <pre><code>&amp;"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /p:Configuration=Debug "/p:DeployOnBuild=true;PublishProfile=MyProfile" myproject\myproject.csproj
  </code></pre>
  
  <h2>Removing the statements that copy the compiler entirely</h2>
  
  <p>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!</p>