6

Assume I have 3 cs projects in a solution and I import this Common.props file in all 3 csproj files.

Here is my Common.props file that will sit at the solution level, each project in my solution will import this Common.props file, I am trying to figure out how I can set the Externals property on the build server via command line that would call a custom CI.Build file that would also sit at the solution level also. MSBuild is pretty new to me, I did all kinds of searching for an answer to this but nothing I found made 100% sense to me.

   <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
        <PropertyGroup>
           <Externals Condition="'$(Externals)'==''">..\..\..\Externals\</Externals>
           </PropertyGroup>
           <ItemGroup>
               <ThirdPartyLibs Include="$(OutputPath)\*.dll" />
           </ItemGroup>
           <Target Name="BeforeResolveReferences">
           <PropertyGroup>
               <AssemblySearchPaths>$(Externals);$(AssemblySearchPaths)</AssemblySearchPaths>
           </PropertyGroup>
           </Target>
               <Target Name="BeforeBuild">
               <Message Text="$(Externals)"></Message>
           </Target>
           <Target Name="AfterBuild">
               <Message Text="After Build______"></Message>
           </Target>
           <Target Name="CleanDlls" AfterTargets="Clean">
               <Delete Files="@(ThirdPartyLibs)"></Delete>
           </Target>
    </Project>
OutOFTouch
  • 1,017
  • 3
  • 13
  • 30
  • have you tried a google search [C# Passing parameters to MSBuild](https://www.google.com/search?q=c%23+passing+parameters+to+MSBuild&oq=c%23+passing+parameters+to+MSBuild&aqs=chrome..69i57j69i58.342j0j4&sourceid=chrome&es_sm=122&ie=UTF-8) – MethodMan Dec 02 '14 at 23:29
  • Yes I did, I am confused not sure if I need to import the csproj files into the Build file then set this Externals property or if I can set the Externals property commandline with the property switch /p? Like I said up above nothing I read made 100% sense to me. – OutOFTouch Dec 03 '14 at 00:02
  • you can start msBuild with /p option to pass argument : MSBuild.exe /p:Externals="c:\Temp" – Troopers Dec 03 '14 at 10:25
  • @Troopers Can you add that as an answer please, I am trying to do that now using msbuild command line and calling my.csproj, msbuild C:\my.csproj, but the Common.Props file is not being imported into my.csproj when I use the command line to build my.csproj, but it imports when I build my.csproj in visual studio to set the AssemblySearch path. – OutOFTouch Dec 03 '14 at 19:47
  • Hmm, the import of Common.props works command line when I call the solution but not the my.csproj. I wonder if it is because in the my.csproj I do the import of Common.props using the $(SolutionDir) for getting a path to the Common.props. – OutOFTouch Dec 03 '14 at 20:01
  • Yeah that was it I have to use a relative path to the Common.Props file for the import when building the my.csproj directly on the command line. – OutOFTouch Dec 03 '14 at 21:03
  • @Troopers If can add your comment as answer I can mark it as correct. – OutOFTouch Dec 03 '14 at 21:04

1 Answers1

15

Start msBuild with /p option to pass argument :

MSBuild.exe /p:Externals="c:\Temp"

MsBuild command line reference

Troopers
  • 5,127
  • 1
  • 37
  • 64