How to get Visual Studio to execute MsBuild Initia

2020-06-03 07:33发布

Intro

I'm looking for an extension point "execute when VS is loading a project". This should also be incorporatable into a build run from outside of VS. This means it should end up in the msbuild scripts.

MSBuild InitialTargets

Now i have found that MSBuild offers an extension point for executing a target before any other is executed: the <Project InitialTargets="..."/>. This perfectly suits my need for console / build server building. However, with Visual Studio i would prefer if it would also (additionaly) occur when VS loads the solution, too. So i've checked whether this is the case: Yes and No. When i import the following project into my *.csproj's:

  <Target Name="TestOnStart">
      <Warning Text="Hey $(MSBuildProjectName) is being initialised"/>
  </Target>

After loading the solution in VS, the warning does pop up for some projects, but not for all.

Questions

  • How can i get VS to execute the InitialTargets on every load?

Or maybe you can help me answer this, enabling me to find a solution myself ;-):

  • How does VS determine whether to run a build or execute the InitialTargets when loading a project?
    • How can i influence this?

Thank you :)

Addendum:

I've just noticed that if i change one of the solution's project's csproj file externally, VS will ask me whether i want to reload the project. If i choose "reload all projects", it will execute the InitialTargets of all projects. So maybe this has to do something with caching or the like. So the solution to my problem might involve making VS believe that something in the project changed (upon/before loading the solution).

0条回答
登录 后发表回答