question

Cataster-7485 avatar image
0 Votes"
Cataster-7485 asked KatieKilian-9383 published

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


vs-generalvs-msbuild
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DylanZhu-MSFT avatar image
1 Vote"
DylanZhu-MSFT answered KatieKilian-9383 published

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.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

unfortunately it didnt work :/
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 azure build pipeline...

0 Votes 0 ·

Hi @Cataster-7485, we suggest you continue to follow up previous thread on stack overflow, and then you can ask more details which could make it work in your project.

1 Vote 1 ·

will do, thanks!

0 Votes 0 ·
Show more comments