1

I have a bunch of csproj-files for which I want to add a path to search for assembly-references using the AssemblySearchPaths. As they are many project-files I wanted to do this only once for all using a Dirtector.Build.Props in the parent-directory of all my projects.

This is my Directory.Build.props:

<Project>
    <Choose>
        <When Condition="$(JenkinsBuild)== 'true'">
            <PropertyGroup>
                <AssemblySearchPaths>
                   C:\lib; $(AssemblySearchPaths)
                </AssemblySearchPaths>
            </PropertyGroup>
        </When>
    </Choose>
</Project>

When I compile my solution using MSBuild, no reference can be found, not even those from System.

From MSDN I got this:

Directory.Build.props is imported very early in Microsoft.Common.props, and properties defined later are unavailable to it. So, avoid referring to properties that are not yet defined (and will evaluate to empty).

So I assume AssemblySearchPaths is just undefined the time the Directory.Builds.props is invoked.

Is there any other opportunity to add a path to the list of paths to search for assemblies for many projects?

MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111

3 Answers3

1

Sometimes it´s so simple. Instead of messing around with the AssemblySearchPath I can simply add the path directly to the call to MSBUild as shown here:

msbuild MySolution.sln -property:ReferencePath=C:/lib
MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111
1

I'm having a similar problem, hardcoding is a working solution.
Simply copy these paths from Microsoft.Common.targets as following:

  <AssemblySearchPaths>
    {CandidateAssemblyFiles};
    $(ReferencePath);
    {HintPathFromItem};
    {TargetFrameworkDirectory};
    {Registry:$(FrameworkRegistryBase),$(TargetFrameworkVersion),$(AssemblyFoldersSuffix)$(AssemblyFoldersExConditions)};
    {AssemblyFolders};
    {GAC};
    {RawFileName};
    $(OutputPath);
    HardcodedPath;
    AndHardcodedPath;
    AndMoreHardcodedPath
  </AssemblySearchPaths>
SGKoishi
  • 390
  • 2
  • 11
0

I've just ran into the same issue while migrating a rather large solution from old project format to new one. We are still realying on some legacy components which are installed into the GAC on developer machines, and published side by side with the application with Copy Local = True.

My solution was to use the Directory.Build.targets file over the props. At first glance it seems to work just fine, however I don't exactly know when it will get imported by the build system, as it has to targets, only acts like a props file.

Zoltán Tamási
  • 12,249
  • 8
  • 65
  • 93