How to nest a Target within another Target in the .csproj file?

Cataster 641 Reputation points
2020-12-16T16:43:31.83+00:00

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: e

rror MSB4067: The element <PropertyGroup> beneath element <Target> is unrecognized.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,558 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,752 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dylan Zhu-MSFT 6,401 Reputation points
    2020-12-17T02:50:35.197+00:00

    Hi Cataster,

    The target cannot be nested in another target. You could modify your target like this:

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

    Best Regards, Dylan

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our * *documentation* to enable e-mail notifications if you want to receive the related email notification for this thread.**

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful