简体   繁体   中英

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

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 (eg 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM