I am following this blog: http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx
it's linked in this question as answer: Web.Config transforms outside of Microsoft MSBuild?
Every step works as described but I want to call the transformation from a powershell script.
I want to do this command in powershell msbuild trans.proj /t:Demo
I found some forums saying that I should use invoke-expression
When I try I get this error
Powershell:
Invoke-Expression $msbuild transformCommand.proj /t:Demo
Result
Invoke-Expression : Cannot bind argument to parameter 'Command' because it is null.
At D:/Somewhere
+ Invoke-Expression <<<< $msbuild transformCommand.proj /t:Demo
+ CategoryInfo : InvalidData: (:) [Invoke-Expression], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.InvokeExpre
ssionCommand
I also tried:
Invoke-Expression msbuild transformCommand.proj /t:Demo
With result
D:\Somewhere
Invoke-Expression : A positional parameter cannot be found that accepts argument 'transformCommand.proj'.
At D:\Redgate\Communited.Timeblockr.Api\PreDeploy1.ps1:14 char:18
+ Invoke-Expression <<<< msbuild transformCommand.proj /t:Demo
+ CategoryInfo : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand
Small note: this is my first time using powershell.
TransformCommand.proj
<Project ToolsVersion="4.0" DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
<Target Name="Demo">
<TransformXml Source="Web.Test.config"
Transform="transform.xml"
Destination="Web.acceptatie.config"/>
</Target>
</Project>
My questions are: Is this possible? And how is it possible?
Edit:
$a = "Path\transformCommand.proj /t:Demo"
#Invoke-Expression $msbuild $a
Start-Process -FilePath "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" -ArgumentList $a | Write-Host
This actually does everything I need..
Still if there are ways to do this more "indepent" or better ways, please post it.
To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.
With PowerShell you can sequentially execute multiple commands at once or pipe output commands to automate common tasks. Designed for app makers and administrators to automate tasks with environments and associated apps, flows, and connectors.
Make sure you define the PowerShell variable $msbuild as below before calling Invoke-Expression $msbuild
$msbuild = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"
I ended up doing the following to build a solution with multiple parameters
&$msbuildExe ('solution.sln','/verbosity:q','/p:configuration=Release','/t:Clean,Build')
if (!$?) {
echo "!!! ABORTING !!!";pause;exit
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With