Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild enforce HintPath validation

Tags:

msbuild

I often see the situation when assembly references have wrong HintPath and this can cause strange random failures.

For example, you have wrong HintPath, but you have a corresponding assembly in your GAC. It will mean that the project will compile ok on your machine but will fail on others.

In my case it is vise versa, there is a library in GAC even on CI server, so this problem will not detectable by continuous integration.

I am looking for something like custom MSBuild task which will validate all HintPaths and cause build failure if any of them are wrong.

like image 248
mnaoumov Avatar asked Oct 15 '12 02:10

mnaoumov


1 Answers

If you want to fail the build if the hint path is invalid, why not just reference something explicitly? This is SOP at my company due to having lots of versions of the same library.

For example:

    <Reference Include="C:\Path\To\Library\MyReference.dll">
      <Private>False</Private>
    </Reference>

Or, if you want to reference libraries based on some path dynamically, you can set some msbuild property, say, "ExternalLibs" that points to your libraries folder (if you keep libs in source control, etc). Then you can set that property via the command line (when you call msbuild) or give it some default value that each user can override in their .user files, for example.

    <Reference Include="$(ExternalLibs)\MyReference.dll">
      <Private>False</Private>
    </Reference>

This solution is pretty flexible.

like image 152
bbar Avatar answered Oct 06 '22 10:10

bbar