Visualstudio-docs: What are the targets?

Created on 13 Mar 2018  Â·  12Comments  Â·  Source: MicrosoftDocs/visualstudio-docs

I can see that there is a BeforeBuild and AfterBuild target, but what is the full list of targets? There doesn't appear to be any link to mention what targets are available...


Document details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri1 msbuiltech unspecifiesvc

Most helpful comment

I have gone through the Microsoft.Common.CurrentVersion.Targets file and summarized all of the public targets in this pastebin: https://pastebin.com/hgA9Qg1E

For the sake of summarily answering the original question, here are the most common targets defined in the typical project build process:

Build
Rebuild
Clean
Run
Publish
PublishOnly
ResolveReferences
ResolveProjectReferences
ResolveAssemblyReferences
GenerateBindingRedirects
PrepareResources
ResGen
Compile
GenerateManifests
PrepareForRun
CopyFilesToOutputDirectory

And the ones that are intended to be overridden in projects (though keep in mind that the same target can only be overridden once)
BeforeBuild
AfterBuild
BeforeRebuild
AfterRebuild
BeforeResolveReferences
AfterResolveReferences
BeforeResGen
AfterResGen
BeforeCompile
AfterCompile
BeforeClean
AfterClean
BeforePublish
AfterPublish

All 12 comments

@ciaran036 Thanks for your comments! Can you clarify? There is a link to the Target element, which shows all the defined attributes supported for Target. Otherwise, BeforeBuild and AfterBuild specify any named target, based on the Name attribute.

I can try to clarify the initial question:
There doesn't seem to be a comprehensive list of default Targets for MSBuild. For example, I have found in existing code in my job that there are targets for /t:Build and /t:Publish for .sqlproj but I have found no documentation or list of targets that ship with MSBuild by default nor additional properties for those targets (for example, /p:SqlPublishProfilePath for /t:Publish). This is extremely frustrating as it limits the user's ability to really use MSBuild to its full extent. I'm not sure how anyone has figured the default ones out that I've seen online, and none of those people give a list of available default Targets.
There's a full Task Reference in the table of contents for Visual Studio's documentation. Can a similar one be created for Targets?

@seanwhitepc Thanks for the additional context. It may be that the default targets change a lot depending on a wide variety of starting points (what type of project, what template), and also that they change a lot based on updates, and that they are owned by the team that owns the template (so it is somewhat external to MSBuild itself). @rainersigwald for input

It's impossible to have a full, complete list, but we could and probably should put a sketch of the common.targets things and their intentions up. That's "documented" in comments there (but those need to be edited quite a bit).

I'm not sure how anyone has figured the default ones out that I've seen online

Mostly via the difficult mechanism of reading the targets files. (I'm not saying that's a good experience.)

I concur, this should be clearly enumerated, documented, etc.

I have gone through the Microsoft.Common.CurrentVersion.Targets file and summarized all of the public targets in this pastebin: https://pastebin.com/hgA9Qg1E

For the sake of summarily answering the original question, here are the most common targets defined in the typical project build process:

Build
Rebuild
Clean
Run
Publish
PublishOnly
ResolveReferences
ResolveProjectReferences
ResolveAssemblyReferences
GenerateBindingRedirects
PrepareResources
ResGen
Compile
GenerateManifests
PrepareForRun
CopyFilesToOutputDirectory

And the ones that are intended to be overridden in projects (though keep in mind that the same target can only be overridden once)
BeforeBuild
AfterBuild
BeforeRebuild
AfterRebuild
BeforeResolveReferences
AfterResolveReferences
BeforeResGen
AfterResGen
BeforeCompile
AfterCompile
BeforeClean
AfterClean
BeforePublish
AfterPublish

Thanks @lostromb!

Because of the last-override-wins policy, I reccomend _not_ overriding any of those targets; instead BeforeTargets/AfterTargets them and leave them as stubs. That's different from the original guidance but works more reliably.

Great start! How about for outer/inner loop targets? i.e. multi-target framework targets?

Thanks @lostromb .

@microsoft, Can we please put this on a documentation page rather than just in a issue comment?

It is worth mentioning a list of pre-defined and overridable targets.

You can put it here on this page or perhaps create a page at docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-targets

Per conversation above, the list of common targets was added to the page.

please-close

@simoncal , I don't see the list on https://docs.microsoft.com/en-gb/visualstudio/msbuild/msbuild-targets?view=vs-2019 .

Which page are you referring to?

I too see no updates to the docs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tpodolak picture tpodolak  Â·  3Comments

wittelw picture wittelw  Â·  3Comments

realbart picture realbart  Â·  3Comments

suhailmahmood picture suhailmahmood  Â·  3Comments

Ogglas picture Ogglas  Â·  3Comments