PowerShellProTools.targets(5,5): error : Unable to find the specified file

I am trying to build my application with PowerShell 7.0.0 or 7.0.1

I get the following error.

PowerShellProTools.targets(5,5): error : Unable to find the specified file.

From the build log:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\PowerShell Tools for Visual Studio\PowerShellProTools.targets(5,5): error MSB4018: The “PowerShellPackageTask” task failed unexpectedly.
System.Exception: Invalid .NET Versions specified for selected PowerShell version. Valid values are: netcoreapp31
at PowerShellToolsPro.Packager.ValidateStage.ValidateDotNetVersion(PackageProcess process)
at PowerShellToolsPro.Packager.ValidateStage.Execute(PackageProcess process, StageResult previousStage)
at PowerShellToolsPro.Packager.PackageProcess.Execute()
at PowerShellToolsPro.MsBuild.PowerShellPackageTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()
Done building project “Speedy.pssproj” – FAILED.

Build FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

So I found out I had PowerShell 7.1.0, So I uninstalled and downgraded to 7.0.1 but now I get this error. One’s the same and ones new.

Unhandled Exception: System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
at Mono.Cecil.PE.ImageReader.ReadOptionalHeaders(UInt16& subsystem, UInt16& dll_characteristics)
at Mono.Cecil.PE.ImageReader.ReadImage()
at Mono.Cecil.PE.ImageReader.ReadImage(Disposable`1 stream, String file_name)
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
at Obfuscar.AssemblyInfo.LoadAssembly(String filename)
at Obfuscar.AssemblyInfo.FromXml(Project project, XmlReader reader, Variables vars)
at Obfuscar.Project.FromXmlReadNode(XmlReader reader, Project project)
at Obfuscar.Project.FromXml(XmlReader reader, String projectFileDirectory)
at Obfuscar.Obfuscator.LoadFromReader(XmlReader reader, String projectFileDirectory)
at Obfuscar.Obfuscator…ctor(String projfile)
at Obfuscar.Program.Main(String[] args)

D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\PowerShell Tools for Visual Studio\PowerShellProTools.targets(5,5): error MSB4018: The “PowerShellPackageTask” task failed unexpectedly.
System.ComponentModel.Win32Exception (0x80004005): Unknown error (0xe0434352)
at PowerShellToolsPro.Packager.Obfuscator.RunObfuscar(String configurationFile)
at PowerShellToolsPro.Packager.Obfuscator.Obfuscate(String assemblyPath, String destinationPath)
at PowerShellToolsPro.Packager.ObfucatorStage.Execute(PackageProcess process, StageResult previousStage)
at PowerShellToolsPro.Packager.PackageProcess.Execute()
at PowerShellToolsPro.MsBuild.PowerShellPackageTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()
Done building project “Speedy.pssproj” – FAILED.

There is a bug in the obfuscator. If you turn this off, you should be able to compile.

I compiled in VS2019 with the Package and Bundle settings checked. My PS Version is set to 7.0.1 and .NET version is .netcoreapp3.1.

image

1 Like

Ya! That seems to have fixed the issue. Any idea of what the bug is with obfuscator that is causing the issue? I kind of need that beautiful feature. lol

Unfortunately, the obfuscator we are using has a bug that is preventing it working with .NET Core. I need to figure out if we need to try something else or see if we can work with the project to move along .NET Core support.

Alright. That solves the issue of building and running the program within Visual Studio.
However, when running outside of Visual Studio as a stand alone exe, you get this error. I had to enable console to find this since it would just simply never load the exe. This is the first error and the rest of the errors are related to unable to load objects since it wasn’t able to load the form.

MethodInvocationException:
Line |
250 | [void][System.Reflection.Assembly]::Load('System.Windows.Forms, Versi …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling “Load” with “1” argument(s): “Could not load file or assembly ‘System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’. Operation is not supported. (0x80131515)”