Question

Can anyone help me to know how can we invoke msbuild default target from a Powershell script?

msbuild script:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="TestMethod">
   <Target Name="TestMethod">
      <Message Text="Test Method Invoke Finished..." Importance="high"/>
   </Target>
</Project>

I want to invoke the target TestMethod from a Powershell script.

Thanks & Regards, Santosh Kumar Patro

Was it helpful?

Solution 2

I was able to find the solution to invoke the msbuild default target (i.e. target =TestMethod) from a powershell script. Please find the example below :

Powershell Script:

MSBUILD Path

$msbuildexe = (get-itemproperty -path "HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0").MSBuildToolsPath + 'msbuild.exe'

Function to Invoke TestMethod

function Invoke-TestMethodFromPowershell([string]$testProjFile) { echo "Calling msbuild Started ..." &$msbuildexe $testProjFile echo "Calling msbuild Completed ..." }

Invoke-VeracodeScanSubmissionProcess("C:\Temp\HelloWorldTest\TestBuild.proj");

Screenshot: enter image description here

OTHER TIPS

Just call

msbuild /path/to/projectfile

If you do not specify a target, msbuild automatically picks the DefaultTargets. Or if that is not available, it calls the first one encountered.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top