PowerShell/docs/building/windows-full.md
Andrew Schwartzmeyer ea5d5c3d05 Switch to netcoreapp1.0
Instead of using `dotnet publish`, we can use `dotnet build` and the new
`netcoreapp1.0` framework with a new dependency on
`Microsoft.NETCore.App` to generate output that does not include the
runtime, but can be run anywhere (given the installation of the
runtime).

While we cannot yet adopt a dependency on the shared host until .NET
Core RTM, we are forced to switch to this system anyway because the
latest RC3 packages and CLI do not support `netstandardapp1.5`. See
dotnet/cli#2482.

Thus we're in an in-between state where we have to use `netcoreapp1.0`,
but cannot use `"Microsoft.NETCore.App": { "type": "platform" }` to
utilize the shared host, as we need to continue to ship our host.
Without specifying "platform", we retain the status quo with respect to
build steps and outputs.

Additionally, there is no longer a good reason to use the RC3 packages,
and it has been advised we switch to RC2 since the
`Microsoft.NETCore.App` is only available for RC2. We must update
packages because our current version can no longer be debugged.
2016-04-25 14:01:44 -07:00

3.4 KiB

Build PowerShell on Windows for .NET Full

This guide supplements the Windows .NET Core instructions, as building the .NET 4.5.1 (desktop) version is pretty similar.

Environment

In addition to the dependencies specified in the .NET Core instructions, we need:

Install the Visual C++ Compiler via Visual Studio 2015.

This component is required to compile the native powershell.exe host.

This is an optionally installed component, so you may need to run the Visual Studio installer again.

If you don't have any Visual Studio installed, you can use Visual Studio 2015 Community Edition.

Compiling with older versions should work, but we don't test it.

Troubleshooting note: If cmake says that it cannot determine the C and CXX compilers, you either don't have Visual Studio, or you don't have the Visual C++ Compiler component installed.

Install CMake and add it to PATH.

You can install it from Chocolatey or manually.

choco install cmake.portable

Build using our module

Use Start-PSBuild -FullCLR from the PowerShellGitHubDev.psm1 module.

Because the ConsoleHost project (not the Host project) is a library and not an application (in the sense that .NET CLI does not emit a native executable using .NET Core's corehost), it targets the framework netstandard1.5, not netcoreapp1.0, and the build output will not have a runtime identifier in the path.

Thus the output location of powershell.exe will be ./src/Microsoft.PowerShell.ConsoleHost/bin/Debug/netcoreapp1.0/powershell.exe

While building is easy, running FullCLR version is not as simple as CoreCLR version.

If you just run ./powershell.exe, you will get a powershell process, but all the interesting DLLs (such as System.Management.Automation.dll) would be loaded from the Global Assembly Cache (GAC), not your output directory.

@lzybkr wrote a module to deal with it and run side-by-side.

Start-DevPSGithub

This command has a reasonable default to run powershell.exe from the build output folder. If you are building an unusual configuration (i.e. not Debug), you can explicitly specify path to the bin directory

Start-DevPSGithub -binDir .\src\Microsoft.PowerShell.ConsoleHost\bin\Debug\net451

Or more programmatically:

Start-DevPSGithub -binDir (Split-Path -Parent (Get-PSOutput))

The default for powershell.exe that we build is x86. See issue #683.

There is a separate execution policy registry key for x86, and it's likely that you didn't bypass enable it. From powershell.exe (x86) run:

Set-ExecutionPolicy Bypass

Build manually

The build logic is relatively simple and contains the following steps:

  • building managed DLLs: dotnet publish --runtime net451
  • generating Visual Studio project: cmake -G "$cmakeGenerator"
  • building powershell.exe from generated solution: msbuild powershell.sln

Please don't hesitate to experiment.