MSBuild how to pass a parameter to set a property value?
Asked Answered
L

1

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>
Lamrert answered 2/12, 2014 at 23:20 Comment(7)
have you tried a google search C# Passing parameters to MSBuildBackside
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.Lamrert
you can start msBuild with /p option to pass argument : MSBuild.exe /p:Externals="c:\Temp"Matthus
@Matthus 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.Lamrert
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.Lamrert
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.Lamrert
@Matthus If can add your comment as answer I can mark it as correct.Lamrert
M
15

Start msBuild with /p option to pass argument :

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

MsBuild command line reference

Matthus answered 4/12, 2014 at 8:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.