9

Note: Visual Studio 2010 SP1 / MSBuild 4.0

I'm going crazy over this bug, I cannot understand why Visual Studio is behaving this way. I'm writing a custom .targets file for my projects in a particular solution. I've edited the .csproj file to have:

<Include Project="..\MyTargets.targets" />

After Microsoft.CSharp.targets near the bottom of the file. The idea is that this targets file will inject actions to be performed by modifying the _____DependsOn properties just like how PostSharp integrates itself.

After scratching my head at how my targets would not run I decided to run it in the command line with MSBuild and see the nicely formatted color output.

In the command line, my targets run. From visual studio (even using clean/rebuild), my targets do not run.

I've hooked BuildDependsOn to run my targets like this:

<PropertyGroup>
  <BuildDependsOn>
    MyTargetGoesHere;
    $(BuildDependsOn)
  </BuildDependsOn>
</PropertyGroup>

My first thought is that i've got the wrong file. I verified the file, it's the right one. Then I checked to see if it was stale. Let visual studio make some changes, saved, ran. Visual studio's new changes took effect, still didn't run my targets.

So here I'm getting desperate. I put a BLARING SYNTAX ERROR in my targets file. MSBuild explodes, Visual Studio compiles the project successfully.

  • What am I doing wrong?
  • Does Visual Studio not use the MSBuild file?
  • Does it call some super secret target instead of "Build" from Microsoft.Common.targets?
  • Why would msbuild behave one way and studio another, I thought they were designed to work together...
Aren
  • 54,668
  • 9
  • 68
  • 101
  • 3
    did you close and reopen your solution file after making changes to the .targets file? – Brian Kretzler Jul 29 '11 at 16:40
  • Interesting, does Visual Studio cache msbuild files or something? I hadn't closed the solution but I had re-loaded the projects many times. – Aren Jul 29 '11 at 16:45
  • 1
    VS will cache any msbuild files imported by projects. Changes to the projects themselves will cause a reload of the project, but not a reload of the imported files, which is why a solution reload is needed. – Brian Kretzler Jul 29 '11 at 17:54

1 Answers1

12

To summarize the comments above, changes to imported project files do not trigger a reload, nor do changes to the importing project cause a reload of the imports. A solution file reload is needed to capture changes made in an import.

Brian Kretzler
  • 9,748
  • 1
  • 31
  • 28
  • I feel really dumb for not thinking to reload the solution, I assumed reloading the project was enough. It's nice to have clarification that VS caches. Thanks – Aren Jul 29 '11 at 18:47
  • Similar issue and reloading the solution doesn't even work for me. In my ".psproj" file (PowerShell project) I have a blaring `` in my build target; msbuild fails, but build from Visual Studio 2013 succeeds with zero output... – BrainSlugs83 Dec 20 '14 at 03:35