Programmatically Add and Edit Targets in a Visual Studio Project File

I am trying to programmatically add the following Target to my Visual Studio project file.

<Target Name="PostBuildEvent" Condition="'$(PostBuildEvent)'!=''" DependsOnTargets="$(PostBuildEventDependsOn)">
      <Exec WorkingDirectory="$(OutDir)" Command="$(PostBuildEvent)" IgnoreExitCode="true" />
</Target>

I am sure that IVsBuildPropertyStorageor IVsBuildPropertyStorage2will not work, because ProjectItem requires aka a node from an element <ItemGroup>in the project file. I would like to add the above xml outside the element <ItemGroup>.

I am trying to use the Visual Studio SDK to do this, and the documentation and examples of doing this exact thing seem to be missing. Since this post I can’t find a way to do this. I would really like to avoid loading the project file (in this case Test.csproj) as XDocumentor by XmlDocumentadding this target node element. It seems messy and can cause more problems.

As an added bonus, I would also like IgnoreOnExit to highlight one element PostBuildEvent, but I'm sure this is not possible with the elementPostBuildEvent

+3
source share
1 answer

AddTarget ProjectRootElement Microsoft.Build.Construction. MSBuild.

+2

Source: https://habr.com/ru/post/1781688/


All Articles