0

Long story short, I need to kill the VBCSCompiler.exe on a Azure pipeline Ubuntu agent after the nuget restore task is completed. On windows2019 agent i dont need to do that but on ubuntu i am running into an issue:

/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 according to Levi in this post here, I need to add a <Target Name="CheckIfShouldKillVBCSCompiler"> lines to the .csproj file. i added them like this:

...
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">
   </Target>
   <Target Name="AfterBuild">
   </Target> -->
   <Target Name="CheckIfShouldKillVBCSCompiler">
     <PropertyGroup>
       <ShouldKillVBCSCompiler>true</ShouldKillVBCSCompiler>
     </PropertyGroup>
   </Target>
 </Project>

But that didnt do anything to unlock the /bin/roslyn path.

I am thinking that this has to be added in the BeforeBuild target lines (e.g. nest them), so i attempted this:

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

But i ended up with error: error MSB4067: The element <PropertyGroup> beneath element <Target> is unrecognized.

Cataster
  • 3,081
  • 5
  • 32
  • 79
  • Did you try that to see if it would work? What was the output? – Dan Csharpster Dec 15 '20 at 15:45
  • @DanCsharpster just tried it, i got an error: `error MSB4067: The element beneath element is unrecognized. ` – Cataster Dec 15 '20 at 15:56
  • Rather than this silly one-path-Linux stuff, you should have an easier time referencing the compiler nuget package, which will clone the Roslyn compiler in your project and use that. – Blindy Dec 15 '20 at 15:59
  • The answer here might be useful for you. https://social.msdn.microsoft.com/Forums/vstudio/en-US/d86ec8ac-c69a-4b04-bd96-78f96c67d32a/all-targets-not-being-called-nested-targets-not-being-executed?forum=tfsbuild – Dan Csharpster Dec 15 '20 at 16:00
  • @Blindy interesting, could you elaborate? – Cataster Dec 15 '20 at 16:02
  • Just reference `Microsoft.Net.Compilers.Toolset`, there isn't anything to elaborate, it's dead simple. – Blindy Dec 16 '20 at 16:04
  • @Blindy where do i reference it? the .csproj file? and whats the syntax to reference it? I only found installing it through nuget PM, but cant find referencing it – Cataster Dec 16 '20 at 16:25
  • Right click on the "depdendencies" node in your solution view, click on "manage nuget packages", "browse", type `Microsoft.Net.Compilers.Toolset`, click on it in the list and click install. – Blindy Dec 16 '20 at 16:43
  • @Blindy i can't do that because i didnt create the project. i am only tasked with building the pipeline, so all i have at my disposal is the bitbucket source. I didnt want to modify anything but if adding the Target per Levi's suggestions can resolve the Roslyn locking problem after nuget restore, then im willing to at least edit the file and commit it on bitbucket. – Cataster Dec 16 '20 at 16:47
  • So wait, you can't modify the `.csproj`, but you can? I mean by all means, do as you wish, but you're saying a whole lot of stuff as it if were true when it's just you setting arbitrary limitations to yourself. – Blindy Dec 16 '20 at 17:11
  • @Blindy I can edit/modify the files on bitbucket but what i am saying I cant do is install the Toolset dependency on visual studio per your recommendation. That's why I thought you meant by referencing that I include a couple lines in the .csproj file or packages file but since you said I actually had to install, that's something I cant do – Cataster Dec 16 '20 at 17:16
  • You can edit it by hand if you wish, the Nuget package manager in VS is just a GUI for editing the relevant portions of the `.csproj`. I have literally no idea where you got anything related to installing anything, all I've been saying is you need to reference a nuget package. I **strongly** recommend stopping whatever it is you're doing and learning how .Net, Nuget and VS/msbuild work first before you break things more than you help. – Blindy Dec 16 '20 at 17:28
  • @Blindy thats what im looking for, editing it by hand :) how do i include the reference and in what file? if you can guide me to the right resources thatd be great – Cataster Dec 16 '20 at 17:37

1 Answers1

0

Ive learned from this answer that this cannot be accomplished.

The target cannot be nested in another target. Instead, the target can be modified like this:

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

However, this did not help resolve the original build issue i had. What did is a different approach found here

Cataster
  • 3,081
  • 5
  • 32
  • 79