Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Ignoring MSBuild file (csproj) Customizations

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...
like image 695
Aren Avatar asked Feb 03 '23 15:02

Aren


1 Answers

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.

like image 164
Brian Kretzler Avatar answered Feb 06 '23 07:02

Brian Kretzler