PowerShellProTools.targets(4,5): error : Failed to build

I’ve inherited a PS forms application that we’ve been using PowerShell Pro Tools to build into an exe, but for the life of me I can’t get it to build an executable.

VS2019 and all the bits on the system requirements are installed (.NET 4.7.2, 4.7.2 Dev Pack, .NET Core 3.1) but when I go to build the solution as an exe via MSBuild I get:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\PowerShell Tools for Visual Studio\PowerShellProTools.targets(4,5): error : Failed to build.

I’ve created a blank PS Forms project and that builds fine and if I un-tick “Package as Executable”, then the script builds fine as a PowerShell script.

I turned on diagnostic logging for PS tools in VS but the log in %APPDATA%\PowerShell Tools for Visual Studio has nothing useful.

Is this a known issue and if not, how can I get some more info about why the project is failing to build?

Is there any other output in the output pane? If so, could you paste that here?

Nothing obvious:

------ Build started: Project: User-Creation-Tool, Configuration: Release Any CPU ------
	Checking license
	OutputPath is C:\Users\alex.pimperton\Documents\GitHub\script-user-creation-tool\User-Creation-Tool\bin\Release\
	Bundling User-Creation-Tool.ps1
	Packaging C:\Users\alex.pimperton\AppData\Local\Temp\User-Creation-Tool.ps1
	Checking dotnet version.
	3.1.101

	Creating package project.
	Using .NET Framework version: net472
	  Restore completed in 172.09 ms for C:\Users\alex.pimperton\AppData\Local\Temp\d9bda46efde2407489c9a1a781faabab\User-Creation-Tool.csproj.

	Packaging C:\Users\alex.pimperton\AppData\Local\Temp\User-Creation-Tool.ps1 -> C:\Users\alex.pimperton\Documents\GitHub\script-user-creation-tool\User-Creation-Tool\bin\Release\\User-Creation-Tool.exe
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\PowerShell Tools for Visual 
Studio\PowerShellProTools.targets(4,5): error : Failed to build.
Done building project "User-Creation-Tool.pssproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I’ve also tried dropping down to .net 4.6.2 (I’ve also got the Dev pack for that installed) but same issue.

The referenced file and line number appears to be where the the package task variables are set:

<PowerShellPackageTask PackageEntryPoint="$(PackageEntryPoint)" 
                       PackageAsExecutable="$(PackageAsExecutable)" 
                       DotNetVersion="$(DotNetVersion)" 
                       Bundle="$(Bundle)" 
                       OutputDirectory="$(OutputPath)" 
                       Obfuscate="$(Obfuscate)"
                       HideConsoleWindow="$(HideConsoleWindow)"
                       FileVersion="$(FileVersion)"
                       FileDescription="$(FileDescription)"
                       ProductName="$(ProductName)"
                       ProductVersion="$(ProductVersion)"
                       Copyright="$(Copyright)"
                       RequireElevation="$(RequireElevation)"
                       ApplicationIconPath="$(ApplicationIconPath)"
                       PackageModules="$(PackageModules)"
                       PackageType="$(PackageType)"
                       ServiceName="$(ServiceName)"
                       ServiceDisplayName="$(ServiceDisplayName)"
                       HighDPISupport="$(HighDPISupport)"
                       PowerShellArgs="$(PowerShellArgs)"
                       PackagePlatform="$(PackagePlatform)"/>

I wondered if I was missing something obvious in the project file but I’ve flipped the various packaging options on and off to see if makes a difference without success.

I just took a peek at the code and the MSBuild task is eating the actual error and throwing that “Failed to build” error. I made a change that should provide us with more details. Running a build now. I can upload a new kit in about 30 minutes after CI runs and we can see if we can get some more info from your environment.

Give this VSIX a try: https://send.firefox.com/download/d4af63563906981c/#DX_7ZHfVIPeuas0vhII1Sw

Thanks for this.

That build produced the actual error (Wrong path to the Icon file) which I’ve corrected and it now builds correctly.