Search code examples
powershellmsbuildtfsbuild

Run a powershell script from TFSBuild.Proj file


I have added a code piece in my MS build file to run a powershell script. But while building it gives me a error error MSB4067: The element "Exec" beneath element "Project" is unrecognized.

Below is the code:

<PropertyGroup>
  <PowerShellExe Condition=" '$(PowerShellExe)'=='' ">
    %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe
  </PowerShellExe>
  <ScriptLocation Condition=" '$(ScriptLocation)'=='' ">
    D:\Synopsis\SynopsysDetect.ps1
  </ScriptLocation>
  </PropertyGroup>
  <Exec Command="%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy Unrestricted -command ^&quot;^&amp; {^&amp;&apos;D:\Synopsis\SynopsysDetect.ps1&apos;} ^&quot;" />

Not sure if the issue is with code or have I placed the code piece at the wrong place. Any help would be appreciated. Thanks.


Solution

  • Moving the above piece of code completely into the "Target" tag fixed the issue.