psbuild
psbuild copied to clipboard
Support for PowerShell Core
I just came across psbuild and am very interested in it. However, having recently moved to PowerShell Core for portability reasons, I wanted to give psbuild a spin under PS Core 6.0.0.9-beta.
PS C:\Kellekek\Microsoft\PowerShell\6.0.0.9> Install-Module Invoke-MsBuild
PackageManagement\Install-Package : Could not compare "6.0.0-alpha" to "5.0". Error: "Cannot convert value "5.0" to typ
e "System.Management.Automation.SemanticVersion". Error: "Cannot process argument because the value of argument "versio
n" is not valid. Change the value of the "version" argument and run the operation again.""
Trying with the self-installing script:
PS C:\Users\Matty\Desktop> Invoke-WebRequest https://raw.githubusercontent.com/ligershark/psbuild/master/src/GetPSBuild.ps1 -OutFile GetPSBuild.ps1
PS C:\Users\Matty\Desktop> .\GetPSBuild.ps1
Method invocation failed because [System.Environment] does not contain a method named 'GetFolderPath'.
At C:\Users\Matty\Desktop\GetPSBuild.ps1:188 char:9
+ $systemDir = [Environment]::GetFolderPath('System')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
New-Object : Cannot find type [System.Net.WebClient]: verify that the assembly containing this type is loaded.
At C:\Users\Matty\Desktop\GetPSBuild.ps1:105 char:14
+ (New-Object System.Net.WebClient).DownloadFile($nugetDown ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
psbuild not found, and was not downloaded successfully. sorry.
Check your nuget.config (default path=C:\Users\Matty\AppData\Roaming\NuGet\NuGet.config) file to ensure that nuget.org
is enabled.
You can also try changing the versionToInstall value.
You can file an issue at https://github.com/ligershark/psbuild/issues.
At C:\Users\Matty\Desktop\GetPSBuild.ps1:177 char:13
+ throw ("psbuild not found, and was not downloaded success ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (psbuild not fou...psbuild/issues.:String) [], RuntimeException
+ FullyQualifiedErrorId : psbuild not found, and was not downloaded successfully. sorry.
Check your nuget.config (default path=C:\Users\Matty\AppData\Roaming\NuGet\NuGet.config) file to ensure that nuge
t.org is enabled.
You can also try changing the versionToInstall value.
You can file an issue at https://github.com/ligershark/psbuild/issues.
MSBuild now being able to build on OSX and Linux using .Net Core, it would be nice if psbuild followed the example.
I haven't had a chance to try this with PS Core. I would love to support it, any chance you can help me with that?
Sure thing. I am no PS guru, but I can do a few things. I'll try to find alternate C# calls that actually exist on .NET Core and point them out. Maybe try the first pull request of my life.
Sweet, thanks a bunch!
I've had a bit of trouble getting to debug PS Core with VS and the PS Add-In, but will give it a shot with VS Code, which supports debugging it.
Ok let me know if I can help. Did u see the build script in the root?
I did, but even the build script fails. A few system related C# calls are either missing from PS Core or have a different name. It should be fairly straight forward once I have an environment running. I just spent roughly an hour trying to familiarize myself with VS Code, first with the C++ and CMake extensions (as that is my primary interest), but the PS extension is also installed, just not yet configured.
Shoud I have any sensible questions, I'll let you know.
@MathiasMagnus thanks for the investigation.
I was thinking about this yesterday (see PS below) and I can think of the following issues with the current code.
- Types are added from the GAC using Add-Type, for example https://github.com/ligershark/psbuild/blob/dev/src/psbuild.psm1#L559.
- Get-MSBuild https://github.com/ligershark/psbuild/blob/dev/src/psbuild.psm1#L217 uses the registry to find MSBuild
Also I think the build script itself may have some xplat issues. I think to investigate the easiest way to start is:
- Run build script on a windows box
- Take files from
OutputRoot\_psbuild-nuget\tools
to the mac and then try loading thepsbuild.psm1
file and see what happens.
For xplat I'm not sure how we can figure out where msbuild is installed. I'll send an email to folks on the MSBuild team to see if I can figure that out. If you email me ([email protected]) I'll add you to that thread.
For the loading of the assemblies in the gac, that is only used when debugMode
is passed to Invoke-MSBuild
. That's an advanced scenario and I think it's OK to limit that to windows for now. So I think we can move the Add-Type
to the block of code that actually uses debugMode
(here).
PS. Coincidentally I had lunch yesterday with Jeffrey Snover (the inventor of PowerShell) and I told him that we are looking to move psbuild to support PS Core. He was happy to hear that :)
FYI the msbuild team has posted https://github.com/Microsoft/msbuild/issues/1039 which should enable us to acquire the msbuild runtime.
@MathiasMagnus I've started some work to see if we can support PowerShell core. One of the challenges is just getting the bits setup to enable dev/test on linux. I made some changes to ensure that PSBuild is now self-contained via #81. Previously it would use nuget.exe
to download dependencies, but that just complicates the setup/experience.
The MSBuild team published the msbuild assembly in the nuget package Microsoft.Build.Runtime. You can download the latest nuget package using nuget.exe
(or nuget-powershell). I've made a version of it available at https://dl.dropboxusercontent.com/u/40134810/psbuild/Microsoft.Build.15.1.262-preview5.nupkg. I think you'll also need Microsoft.Build.Runtime
and I have a version for download at https://dl.dropboxusercontent.com/u/40134810/psbuild/Microsoft.Build.Runtime.15.1.262-preview5.nupkg.
I've also created a new branch pscore
.
To try out this branch in the current state:
- Download the
Microsoft.Build
NuGet package and extract the contents using a zip tool - Clone repo
- Switch to
pscore
branch - Set
$env:MSBuildPath
to the folder withMicrosoft.Build.15.1.262-preview5\lib\netstandard1.5
from the NuGet package - Import-module
src\psbuild.psm1
- Call
Set-MSBuild
and pass the path to msbuild.exe that you want to use (msbuild.exe can be found in the Microsoft.Build.Runtime package)
The known work to support core looks like:
- [ ] Missing api:
[System.Security.Cryptography.HashAlgorithm]::Create
- [ ] Include
Microsoft.Build.Runtime
as a dependency in the psbuild nuget package itself. Should follow similar pattern as my recent changes forfile-replacer
https://github.com/ligershark/psbuild/commit/c08a4026f5193a636faa22a07e6d9fb91a3a80f9 - [ ] Update calls to
Add-Type
pointing to the NuGet package assemblies - [ ] There is a call to
Add-Type System.Core
which throws https://github.com/ligershark/psbuild/blob/master/src/psbuild.psm1#L1442
Hi!
Thanks for the efforts! My resources have been slightly overallocated. I will try to contribute with actual code, as time allows. I have another build system-related contribution (batch-mode rule support for the NMake generator of CMake) where I finally pinpointed the place where I could insert the required code.