0

I created an Azure Devops Build pipeline and i am trying to build my ASP.NET MVC and Angular hybrid site project on bitbucket (git).

The project first gets checked out, and nuget restores the necessary packages, and then the .NET builds. I used windows 2019 as azure pipeline agent for the build to succeed. however, Its taking about 7 minutes to complete, whilst running the tasks (besides .Net) on a ubuntu agent is much faster! takes around 2 mins instead!

Therefore, I'd like to use ubuntu, but im running into an issue with the MSBuild task...

"/home/vsts/work/1/s/Bobby.ProjectA/Bobby.ProjectA.csproj" (default target) (1) ->
(KillVBCSCompilerAndRetryCopy target) -> 
/home/vsts/work/1/s/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8/build/net45/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props(23,5): 
error MSB4044: The "KillProcess" task was not given a value for the required parameter "ImagePath". [/home/vsts/work/1/s/Bobby.ProjectA/Bobby.ProjectA.csproj]

According to this post, VBCSCompiler.exe continues running from the Compiler Nuget package (nuget restore task?) so it locks the src folders and prevented future builds from running, e.g. causing error like this:

/home/vsts/work/1/s/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8/build/net45/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props(17,5): 
warning MSB3021: Unable to copy file "/home/vsts/work/1/s/packages/Microsoft.Net.Compilers.2.4.0/build/../tools/csc.exe" to "/bin/roslyn/csc.exe". Access to the path '/bin/roslyn' is denied. [/home/vsts/work/1/s/Bobby.ProjectA/Bobby.ProjectA.csproj]

So the solution would be to kill the VBCSCompiler.exe but since i cant actually access the hosted machine during the build, im not sure how to do that.

screenshot of my pipeline so far:

pipeline

Am i facing a dead-end path here with this approach? The build runs fine on windows 2019 but it just takes too long, so thats why if i can make it run on ubuntu successfully that would be great!

Cataster
  • 3,081
  • 5
  • 32
  • 79

2 Answers2

0

You can have a try with below workarounds:

1,Set MSBUILD arguements /p:UseSharedCompilation=false.

You can add above arguement to the msbuild arguements field of the msbuild task. See here.

enter image description here

2,Upgrade Microsoft.CodeDom.Providers.DotNetCompilerPlatform nupkg to the latest and remove Microsoft.Net.Compilers nupkg from your project. See here for more information.

3, Try Specifing the TTL of Roslyn compiler server.

You can define a pipeline variable VBCSCOMPILER_TTL on the Variable tab to specify a shorter idle time for VBCSCompiler.exe

Or you can add <providerOption name="CompilerServerTimeToLive" value="[num of seconds]" /> under system.codedom/compilers/compiler in the config file. See here for more information.

4, Use CheckIfShouldKillVBCSCompiler target:

You can try add below to your csproj file:

<Target Name="CheckIfShouldKillVBCSCompiler">
  <PropertyGroup>
    <ShouldKillVBCSCompiler>true</ShouldKillVBCSCompiler>
  </PropertyGroup>
</Target>

See here.

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • Levi, how do i nest the Target (option 4) in the before build target? please find my post here about it: https://stackoverflow.com/questions/65308692/how-to-nest-a-target-within-another-target-in-the-csproj-file – Cataster Dec 16 '20 at 15:44
  • @Cataster You can try using [BeforeTargets attribute](https://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-extend-the-visual-studio-build-process?view=vs-2019#example-aftertargets-and-beforetargets). eg. ``. or setting the [InitialTargets](https://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-specify-which-target-to-build-first?view=vs-2019) eg.``. – Levi Lu-MSFT Dec 17 '20 at 02:07
  • The BeforeBuild targets didnt work. I also tried `BeforeTargets="Build"` and that didnt work either. I also tried putting the property group inside the BeforeBuid Target itself but that didnt work either. I want to attempt the inititialtargets you proposed, but where do i add it? There is only 1 project element and it already has a default target...is it ok to override it? or do i just have to include it along with it like this: `` – Cataster Dec 17 '20 at 04:11
  • its not working either way. i have one last option: restarting the build agent before the MSBuild task, but idk what task to add/how to restart the ubuntu agent on the pipeline... – Cataster Dec 17 '20 at 04:33
  • @Cataster You cannot restart the agent during the pipeline execution. You can try adding a bash task before MSbuild task to kill the VBCSCompiler.exe process. `killall VBCSCompiler`. see [here](https://itsfoss.com/how-to-find-the-process-id-of-a-program-and-kill-it-quick-tip/) – Levi Lu-MSFT Dec 17 '20 at 05:43
  • i got this error: `VBCSCompiler: no process found` – Cataster Dec 17 '20 at 05:48
  • I am stuck right now. If the VBCSCompiler process is not really running, then why `Access to the path '/bin/roslyn' is denied.`? this post here makes it sounds like its definitely a VBCSCompiler issue, which is why i have been attempting all these options for so long now. but if this whole time this isnt really the issue the access is denied, then what could possibly be the issue? https://developercommunity.visualstudio.com/content/problem/71302/binroslyn-files-locked-during-build.html?page=2&pageSize=10&sort=votes&type=problem – Cataster Dec 17 '20 at 06:07
0

The build on Ubuntu 20 finally worked! I don't know why removing these lines resolved the VBCSCompiler issue, but by doing so, the msbuild completed successfully on Ubunutu 20 agent!!

Remove the following lines from the .csproj file:

<Import Project="..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props')" />

<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />

To give some context to the answer, this post here indicated that converting from MSBuild-Integrated Package Restore to Automatic Package Restore (nuget restore task) implied that the Microsoft.Net.Compilers <Import> and <Error Condition> snippets are no longer relevant/needed in the .csproj file.

Cataster
  • 3,081
  • 5
  • 32
  • 79