Search code examples
.netvisual-studio-2012msbuildcsprojmsbuild-propertygroup

Changes to csproj not taking effect


In an attempt to make my references update based on my configuration, I've tweaked my .csproj file by adding a property and changing all the references to use it as follows:

<PropertyGroup>
    <ReferencePath Condition=" '$(Configuration)' ==  'Release'">foo\release\1.0.0.9\bin\</ReferencePath>
    <ReferencePath Condition=" '$(Configuration)' == 'Debug'">bar\debug\</ReferencePath>
</PropertyGroup>

<Reference Include="BasicControls, Version=5.0.53.0, Culture=neutral, PublicKeyToken=25ad4b03c913ffff, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>$(ReferencePath)\BasicControls.dll</HintPath>
</Reference>

Something is wrong and preventing the changes from propagating. Nothing I do to the .csproj file changes the paths of the references - no matter what I do, right-clicking on the reference and looking at its Path in the properties shows the same path it showed before I started editing the file.

  • I've tried unloading and reloading the project
  • I've tried changing the configuration from Debug to Release
  • I've opened and closed the solution
  • While the solution was closed, I deleted the .suo file.
  • I've clicked reload on the solution explorer.

All of the references in the .csproj use the $(ReferencePath) setup, and neither of my ReferencePaths use the original path.

What am I missing? Is it something in the way I'm using the Property?


Solution

  • As I mentioned in the comments, I think stijn has provided a lot of good information on how to debug issues with a .csproj file. Some of his more basic ones helped me resolve my issue. Since stijn hasn't posted all the information in the comments as an answer for me to accept, I'm summarizing it and making it a community wiki.

    • The simplest thing that helped get me on track was exiting VS between edits of the .csproj. I had been closing the solution and reopening it, but somehow there were different results. So, always exit VS if you're worried your changes aren't propagating.

    • I've seen the .suo file cause some strange caching issues, where paths my file no longer refers to are still appearing. To keep things as clean as possible, after you exit VS, delete the .suo. It's just a preferences cache; deleting it doesn't make you lose anything.

    • If you want to debug a variable, you can put the following code inside a .csproj:

      <Target Name="ShowRefPath" BeforeTargets="Build"> <Message Text="$(MyRefPath)"/> </Target>

    where MyRefPath is the variable you are interested in looking at. It will then appear in your output log when you build, if you set the output log filter to Normal or higher.

    • I found that setting the output log filter (at Tools->Options->Projects and Solutions->MSBuild project output verbosity) to Detailed gave me more than enough data to debug my underlying issue. It's very verbose, but that's what you're looking for at that point.

    Of these, the most useful tips for me were setting the output log verbosity and exiting VS instead of closing the solution.