1

In my csproj, I am importing a very large heavily used targets file (which I am not allowed to break down as of now). This targets file however, sets up various target dependencies by using AfterTargets='Build'.

In the csproj where I import this large targets file, I want to remove some of the After build target dependencies. For example, say the following target gets imported:

<!-- This is in the large targets file --> <Target Name="Target1" AfterTargets="Build"> </Target> 

How do I remove Target1 from being executed After build in the csproj I am importing it in. What is a good way to accomplish that?

1 Answer 1

3

You have to overwrite the target Target1 and then set an empty for its target that means you have removed the previous Target1.

Although it still appear on the build log, it is empty with no operation. That is the only way. And if you want to make Target1 not appear, you have to delete it under the large targets file.

You should note that you must write the new Target1 after the previous one to make the new one overwrite the old one.

For an example,

 <!-- This is in the large targets file --> <Target Name="Target1" AfterTargets="Build"> // the old one //do some larget opertion </Target> ........ ........ <Target Name="Target1"> // the new one and make it empty </Target> 
Sign up to request clarification or add additional context in comments.

2 Comments

Clarifying two things : 1. The new definition should be in the csproj after the import of the big targets file? and 2. In the new definition, why is the 'AfterTargets="Build"' needed?
1) Sure. It should be added after Target1 to overwrite the old target no matter at the bottom of the targets file or in the csproj file after import node. 2) Sure. You are right. It quite does not need to AfterTargets="Build". I have updated my answer and you can check it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.