0

Long story short, I was able to build a bitbucket .NET/MVC/Angular project successfully on windows 2019 azure hosted agent, but I am unable to make it build successfully on ubuntu agent. The reason I want to build it on ubuntu is because I noticed the build time is way faster than that of the windows agent, which makes sense considering the platforms.

I am facing this error:

Copying file from "/home/vsts/work/1/s/Bobby.ProjectA/obj/Debug/Bobby.ProjectA.pdb" to "/home/vsts/work/1/s/Bobby.ProjectA/bin/Bobby.ProjectA.pdb".
CopyRoslynCompilerFilesToOutputDirectory:
  Creating directory "/bin/roslyn".
  Creating directory "/bin/roslyn".
  Creating directory "/bin/roslyn".
  Creating directory "/bin/roslyn".

/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]
"/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, the issue is because the VBCSCompiler is locking the src.

So i have exhausted all of these solutions here to kill the VBCCompiler, but none of them worked. I also can't restart the ubuntu agent during a build due to CI limitation, and killall VBCSCompiler bash script before msbuild task resulted in this error: VBCSCompiler: no process found

So now i am sure that this has to do with the last error message on the log which is error MSB4044: The "KillProcess" task was not given a value for the required parameter "ImagePath".

According to this post here, I would need to specify an image path but since this is running on a build agent, I can't do that since i can't simply click on the error message like the person did to open the Microsoft.codeDom.Providers.DotNetCompilerPlatform.props file.

and i couldn't locate this file in the project, so i think it gets created during the build...

and even if am able to specify an image path, what would be the path? /bin/roslyn?

Cataster
  • 3,081
  • 5
  • 32
  • 79
  • From your log, you are still using the older package version:`Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8`. Can you try to update the package to 2.0.1 or latest? Then you could remove the Microsoft.Net.Compilers reference. Here is the release note about the pacage:https://github.com/aspnet/RoslynCodeDomProvider/tags. – Kevin Lu-MSFT Dec 21 '20 at 07:34
  • @KevinLu-MSFT can you tell me how to do that without having to clone the project in visual studio and do it there? Where can I update all references of this manually? I dont see a PROPS file in the project on bitbucket, so which files will I find this reference to update it? – Cataster Dec 21 '20 at 16:13
  • You could check if your project contain a file like `packages.config`. You could change the package version in it. Then you could find the xxx.csproj and change the package reference hintpath in it. – Kevin Lu-MSFT Dec 22 '20 at 06:44
  • @KevinLu-MSFT unfortunately upgrading the version and removing the other reference didnt work. getting an error: `This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. The missing file is ../packages/Microsoft.Net.Compilers.2.4.0/build/Microsoft.Net.Compilers.props. ` i dont have access to that build folder since it clearly gets created on the agent so idk where its trying to reference it from after i already removed the `Microsoft.Net.Compilers` references from `packages.config` as well as `.csproj` file... – Cataster Dec 23 '20 at 06:37
  • You could refer to this ticket: https://stackoverflow.com/a/23852183/13464420 In csproj file you could remove the tag. and check if it still ask for the Microsoft.Net.Compilers package. – Kevin Lu-MSFT Dec 25 '20 at 02:15
  • 1
    @KevinLu-MSFT it worked!!! FINALLY!! i didnt even have to remove `Microsoft.Net.Compilers` references nor did i have to update `Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8` versions in `packages.config` as well as `.csproj` file; all that was needed was removing the error conditions: ` – Cataster Dec 25 '20 at 05:56
  • Great ! Do you mean that it could work on Ubuntn Agent now? – Kevin Lu-MSFT Dec 25 '20 at 06:00
  • 1
    @KevinLu-MSFT yes!! I almost gave up!! I thought for sure it must be because the project is not core project so its not supported on linux, but now that its working, we can dismiss that as a myth! – Cataster Dec 25 '20 at 06:02
  • This is so wonderful ! I think we can turn this method into an answer, which should help many other users. – Kevin Lu-MSFT Dec 25 '20 at 06:05
  • @KevinLu-MSFT honestly, it doesnt make sense to me why removing those error conditions from the .csproj file resolved the issue. like what does that have to do with `Access to the path '/bin/roslyn' is denied.` and `error MSB4044: The "KillProcess" task was not given a value for the required parameter "ImagePath".`. but its working, so im happy, but maybe you could provide a clear answer about this? idk, lmk if you'd like to post an answer or if i should do it, although if i post an aswer, its gonna be generic and i won't be able to explain why this is the resolution – Cataster Dec 25 '20 at 06:08
  • @KevinLu-MSFT just to reiterate for a correct answer if you plan to post one: In order for this .NET project to work on Ubunutu agent, I had to remove the following lines/tagsonly from the .csproj file: `` and ` – Cataster Dec 25 '20 at 06:29

2 Answers2

1

I removed these from .csproj project file and cleared the bin and obj folder. Now it's working as expected.

  <Import Project="..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets" Condition="Exists('..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets')" />

and

  <Error Condition="!Exists('..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets'))" />
Edi
  • 1,900
  • 18
  • 27
0

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

UPDATE:

When running this on windows agent, you will also need to remove the following line as well from the .csproj file

<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />

to resolve these warnings when building on windows agent:

Warning MSB3030: Could not copy the file "\pagefile.sys" because it was not found.
Warning MSB4181: The "Copy" task returned false but did not log an error.
Cataster
  • 3,081
  • 5
  • 32
  • 79