Can I add a common reference path in an MSBuild target/project file?

1.7k views Asked by At

I'm trying to write a custom project (targets?) file that is to be included in several projects.

For example, inside all of my .csproj and .vbproj files I have:

<Import Project="..\MyCustomTargets\custom.targets"/>

Inside that file I have a custom target (AfterBuild) which copies the compiled files to another location.

However, I'd like to add a reference path that each project can look to when trying to resolve references. Is this possible?

For example, I'd like to add something like this to my .targets file:

<AdditionalReferencePath>C:\LookHereForReferences</AdditionalReferencePath>

I've found a few links that describe a little about how to do this but I can't get it working.

1

There are 1 answers

0
Leo Liu On

I'd like to add a reference path that each project can look to when trying to resolve references. Is this possible?

You can set a Property Group in your .targets file:

<PropertyGroup>
  <AdditionalReferencePath>C:\LookHereForReferences</AdditionalReferencePath>
</PropertyGroup>

After import this targets file in to the project file, you can look it by $(AdditionalReferencePath) when trying to resolve references:

  <Import Project="Common.targets" />
  <Target Name="Test" AfterTargets="Build">
    <Message Text="$(AdditionalReferencePath)"></Message>
  </Target>

enter image description here