简体   繁体   中英

Add solution level assembly reference

I have solutions that include dozens of projects (say proj1 through proj50), each referencing a series of the exact same dozen or so assemblies (say asm1 thorugh 12). These assemblies (asm1-asm12) are referenced without a hint path. The solutions (containing proj1-proj50) are maintained by another group so that changing them is less desired (I'm not the owner of neither proj i nor asm i I just want to build the solution).

What I would like to do is put the dozen or so assembly dlls in a place where all projects will see without the need to set the paths individually in each project. In other words I want to avoid repeating same task 600 times for each solution tree. Adding a solution level "solution" will be OK (so I will do a single action for a single sln), doing it w/o changing the solution is even better (single action for perpetuity).

In the solution folder if you add a file named Directory.Build.props that props file will be read in and imported to any project built in the same directory or lower relative to that props file as one of the first things in the file (If you use Directory.Build.targets it will be imported as the last thing in the file)

You can move the project references out of the .csproj and in to that .props file and they will be imported as if they where still in the .csproj

Here is a example of a Directory.Build.props that will cause every project in the solution to include the file lib\\ThirdParty.SomeLibrary.dll as a reference.

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <Reference Include="ThirdParty.SomeLibrary", Version=10.4.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
          <HintPath>$(MSBuildThisFileDirectory)\lib\ThirdParty.SomeLibrary.dll</HintPath>
        </Reference>
    </ItemGroup>
</Project>

You can include the Directory.Build.props file as a solution level file and you will be able to easily open and edit the file from inside visual studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM