Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for PowerShell Core #80

Open
MathiasMagnus opened this issue Aug 25, 2016 · 10 comments
Open

Support for PowerShell Core #80

MathiasMagnus opened this issue Aug 25, 2016 · 10 comments

Comments

@MathiasMagnus
Copy link

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.

@sayedihashimi
Copy link
Member

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?

@MathiasMagnus
Copy link
Author

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.

@sayedihashimi
Copy link
Member

Sweet, thanks a bunch!

@MathiasMagnus
Copy link
Author

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.

@sayedihashimi
Copy link
Member

Ok let me know if I can help. Did u see the build script in the root?

@MathiasMagnus
Copy link
Author

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.

@sayedihashimi
Copy link
Member

@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.

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 the psbuild.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 :)

@sayedihashimi
Copy link
Member

FYI the msbuild team has posted dotnet/msbuild#1039 which should enable us to acquire the msbuild runtime.

@sayedihashimi
Copy link
Member

sayedihashimi commented Oct 18, 2016

@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:

  1. Download the Microsoft.Build NuGet package and extract the contents using a zip tool
  2. Clone repo
  3. Switch to pscore branch
  4. Set $env:MSBuildPath to the folder with Microsoft.Build.15.1.262-preview5\lib\netstandard1.5 from the NuGet package
  5. Import-module src\psbuild.psm1
  6. 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:

@MathiasMagnus
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants