问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/65308692/how-to-nest-a-target-within-another-target-in-the-csproj-file