Additional paths in msbuild script

How to specify additional build reference paths for MSBuild tasks?

I have a script so far, but can't figure out how to specify additional search paths.

<ItemGroup>
 <ProjectsToBuild Include="..\Main\Main.sln" />
</ItemGroup>

<!-- The follwing paths should be added to reference search paths for the build tasks -->
<ItemGroup>
 <MyAddRefPath Include="$(MSBuildProjectDirectory)\..\..\Build\Lib1" />
 <MyAddRefPath Include="$(MSBuildProjectDirectory)\..\..\Build\Lib2" />
</ItemGroup>

<MSBuild
 Projects="@(ProjectsToBuild)"
 Properties="Configuration=Debug;OutputPath=$(BuildOutputPath)">
</MSBuild>

UPDATE:

Please show one full-fledged working script that invokes the original project, such as SLN with a few additional reference paths.

No suggestions on how to improve the structure of the project, please. I know how to build a good structure, but now it's the task of creating an existing piece of crap.

+3
source share
4 answers

I finally figured out how to do this:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<ItemGroup>
    <ProjectsToBuild Include="ConsoleApplication1\ConsoleApplication1.csproj" />
</ItemGroup>

<ItemGroup>
    <AdditionalReferencePaths Include="..\Build\ClassLibrary1" />
    <AdditionalReferencePaths Include="..\Build\ClassLibrary2" />
</ItemGroup>

<PropertyGroup>
    <BuildOutputPath>..\Build\ConsoleApplication1</BuildOutputPath>
</PropertyGroup>

<Target Name="MainBuild">
    <PropertyGroup>
        <AdditionalReferencePathsProp>@(AdditionalReferencePaths)</AdditionalReferencePathsProp>
    </PropertyGroup>
    <MSBuild
        Projects="ConsoleApplication1\ConsoleApplication1.csproj"
        Properties="ReferencePath=$(AdditionalReferencePathsProp);OutputPath=$(BuildOutputPath)"
    >
    </MSBuild>
</Target>

+4
source

, , . , , AssemblySearchPaths. , . ( . . .)

, script :

set AssemblySearchPaths="C:\Tacos;C:\Burritos;C:\Chalupas"
msbuild whatever.msbuild

- PropertyGroup msbuild ( "hook", ):

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <ProjectsToBuild Include="..\Main\Main.sln" />
    </ItemGroup>

    <PropertyGroup>
          <AssemblySearchPaths>$(MSBuildProjectDirectory)\..\..\Build\Lib1;$(MSBuildProjectDirectory)\..\..\Build\Lib2</AssemblySearchPaths>
    </PropertyGroup>

    <Target Name="Build">
        <MSBuild Projects="@(ProjectsToBuild)" Properties="AssemblySearchPaths=$(AssemblySearchPaths);Configuration=Debug;OutputPath=$(OutputPath)" />
    </Target>
</Project>

, , - , , , , IDE, . diff/merge, , mercurial ( , , ).

+1

, , AssemblySearchPaths. . ResolveAssemblyReference.

<Target Name="AddToSearchPaths">  
  <CreateProperty Value="x:\path\to\assemblies;$(AssemblySearchPaths)">  
    <Output PropertyName="AssemblySearchPaths" TaskParameter="Value" />  
  </CreateProperty>  
</Target>

, , :

<Target Name="AddToSearchPaths">  
  <CreateProperty Value="@(MyAddRefPath);$(AssemblySearchPaths)">  
    <Output PropertyName="AssemblySearchPaths" TaskParameter="Value" />  
  </CreateProperty>  
</Target>

% WINDIR%\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets, , ResolveAssemblyReference Task ResolveAssemblyReferences. , , AssemblySearchPaths ResolveAssemblyReferences.

0

... , , , ...

<ItemGroup>
    <MyAddRefPath Include="$(MSBuildProjectDirectory)\..\..\Build\Lib1" />
    <MyAddRefPath Include="$(MSBuildProjectDirectory)\..\..\Build\Lib2" />    
</ItemGroup>
<PropertyGroup>
    <MyAddRefPath>$(MSBuildProjectDirectory)\..\..\Build\Lib3</MyAddRefPath>
    <!-- add in the property path -->
    <AssemblySearchPaths>$(MyAddRefPath);$(AssemblySearchPaths)</AssemblySearchPaths>
    <!-- add in the item paths -->
    <AssemblySearchPaths>@(MyAddRefPath);$(AssemblySearchPaths)</AssemblySearchPaths>
</PropertyGroup>

... , , CreateProperty ( 2.0)

<Target Name="AddToSearchPaths">
    <PropertyGroup>
        <!-- add in the item paths -->
        <AssemblySearchPaths>@(MyDynamicAddRefPath);$(AssemblySearchPaths)</AssemblySearchPaths>
    </PropertyGroup>
</Target>
0

All Articles