2018-02-13 18:23:53 +01:00
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
/ *
2016-03-30 23:20:52 +02:00
* This is the source code for the tool ' TypeCatalogGen . exe ' , which has been checked in % SDXROOT % \ tools \ managed \ v4 . 0 \ TypeCatalogGen .
* The tool ' TypeCatalogGen . exe ' is used when building ' Microsoft . PowerShell . CoreCLR . AssemblyLoadContext . dll ' for OneCore powershell
* to generate the CoreCLR type catalog initialization code , which will then be compiled into the same DLL .
*
* See files ' makefile . inc ' and ' sources ' under directory ' PSAssemblyLoadContext ' to learn how the tool and the auto - generated CSharp
* file is used .
*
* Compilation Note :
* . NET Fx Version - 4.5
* Special Dependency - System . Reflection . Metadata . dll , System . Collections . Immutable . dll ( Available as nuget package : http : //www.nuget.org/packages/System.Reflection.Metadata)
* To compile the code , create a VS project and get the ' System . Reflection . Metadata ' package from nuget . Then add this file to the VS
* project and compile it .
* /
using System ;
using System.Collections.Generic ;
using System.Globalization ;
using System.IO ;
using System.Reflection ;
using System.Reflection.Metadata ;
using System.Reflection.PortableExecutable ;
using System.Security.Cryptography ;
using System.Text ;
namespace Microsoft.PowerShell.CoreCLR
{
public class TypeCatalogGen
{
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
// Help messages
2016-03-30 23:20:52 +02:00
private const string Param_TargetCSharpFilePath = "TargetCSharpFilePath" ;
private const string Param_ReferenceListPath = "ReferenceListPath" ;
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
private const string Param_PrintDebugMessage = "-debug" ;
2016-03-30 23:20:52 +02:00
private const string HelpMessage = @ "
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
Usage : TypeCatalogGen . exe < { 0 } > < { 1 } > [ { 2 } ]
2016-03-30 23:20:52 +02:00
- { 0 } : Path of the target C # source file to generate .
- { 1 } : Path of the file containing all reference assembly paths , separated by semicolons .
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
- [ { 2 } ] : Write out debug messages . Optional .
2016-03-30 23:20:52 +02:00
";
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
// Error messages
2016-03-30 23:20:52 +02:00
private const string TargetSourceDirNotFound = "Cannot find the target source directory. The path '{0}' doesn't exist." ;
private const string ReferenceListFileNotFound = "Cannot find the file that contains the reference list. The path '{0}' doesn't exist." ;
private const string RefAssemblyNotFound = "Reference assembly '{0}' is declared in the reference list file '{1}', but the assembly doesn't exist." ;
private const string UnexpectedFileExtension = "Cannot process '{0}' because its extension is neither '.DLL' nor '.METADATA_DLL'. Please make sure the file is an reference assembly." ;
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
// Format strings for constructing type names
private const string Format_RegularType = "{0}.{1}" ;
private const string Format_SingleLevelNestedType = "{0}.{1}+{2}" ;
private const string Format_MultiLevelNestedType = "{0}+{1}" ;
2016-03-30 23:20:52 +02:00
/ *
* Go through all reference assemblies of . NET Core and generate the type catalog - > Dictionary < NamespaceQualifiedTypeName , TPAStrongName >
2016-06-28 18:59:22 +02:00
* Then auto - generate the partial class ' PowerShellAssemblyLoadContext ' that has the code to initialize the type catalog cache .
2016-03-30 23:20:52 +02:00
*
* In CoreCLR , there is no way to get all loaded TPA assemblies ( . NET Framework Assemblies ) . In order to get type based on type name , powershell needs to know what . NET
* types are available and in which TPA assemblies . So we have to generate the type catalog based on the reference assemblies of . NET Core .
* /
public static void Main ( string [ ] args )
{
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
if ( args . Length < 2 | | args . Length > 3 )
2016-03-30 23:20:52 +02:00
{
string message = string . Format ( CultureInfo . CurrentCulture , HelpMessage ,
Param_TargetCSharpFilePath ,
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
Param_ReferenceListPath ,
Param_PrintDebugMessage ) ;
2016-03-30 23:20:52 +02:00
Console . WriteLine ( message ) ;
return ;
}
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
bool printDebugMessage = args . Length = = 3 & & string . Equals ( Param_PrintDebugMessage , args [ 2 ] , StringComparison . OrdinalIgnoreCase ) ;
2016-03-30 23:20:52 +02:00
string targetFilePath = ResolveTargetFilePath ( args [ 0 ] ) ;
List < string > refAssemblyFiles = ResolveReferenceAssemblies ( args [ 1 ] ) ;
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
Dictionary < string , TypeMetadata > typeNameToAssemblyMap = new Dictionary < string , TypeMetadata > ( StringComparer . OrdinalIgnoreCase ) ;
2016-03-30 23:20:52 +02:00
// mscorlib.metadata_dll doesn't contain any type definition.
foreach ( string filePath in refAssemblyFiles )
{
if ( ! filePath . EndsWith ( ".METADATA_DLL" , StringComparison . OrdinalIgnoreCase ) & &
! filePath . EndsWith ( ".DLL" , StringComparison . OrdinalIgnoreCase ) )
{
string message = string . Format ( CultureInfo . CurrentCulture , UnexpectedFileExtension , filePath ) ;
throw new InvalidOperationException ( message ) ;
}
using ( Stream stream = File . OpenRead ( filePath ) )
using ( PEReader peReader = new PEReader ( stream ) )
{
MetadataReader metadataReader = peReader . GetMetadataReader ( ) ;
string strongAssemblyName = GetAssemblyStrongName ( metadataReader ) ;
foreach ( TypeDefinitionHandle typeHandle in metadataReader . TypeDefinitions )
{
// We only care about public types
TypeDefinition typeDefinition = metadataReader . GetTypeDefinition ( typeHandle ) ;
// The visibility mask is used to mask out the bits that contain the visibility.
// The visibilities are not combineable, e.g. you can't be both public and private, which is why these aren't independent powers of two.
TypeAttributes visibilityBits = typeDefinition . Attributes & TypeAttributes . VisibilityMask ;
if ( visibilityBits ! = TypeAttributes . Public & & visibilityBits ! = TypeAttributes . NestedPublic )
{
continue ;
}
string fullName = GetTypeFullName ( metadataReader , typeDefinition ) ;
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
bool isTypeObsolete = IsTypeObsolete ( metadataReader , typeDefinition ) ;
2016-04-06 21:01:07 +02:00
if ( ! typeNameToAssemblyMap . ContainsKey ( fullName ) )
{
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
// Add unique type.
typeNameToAssemblyMap . Add ( fullName , new TypeMetadata ( strongAssemblyName , isTypeObsolete ) ) ;
}
else if ( typeNameToAssemblyMap [ fullName ] . IsObsolete & & ! isTypeObsolete )
{
// Duplicate types found defined in different assemblies, but the previous one is obsolete while the current one is not.
// Replace the existing type with the current one.
if ( printDebugMessage )
{
var existingTypeMetadata = typeNameToAssemblyMap [ fullName ] ;
Console . WriteLine ( $ @ "
REPLACE ' { fullName } ' from ' { existingTypeMetadata . AssemblyName } ' ( IsObsolete ? { existingTypeMetadata . IsObsolete } )
WITH ' { strongAssemblyName } ' ( IsObsolete ? { isTypeObsolete } ) ");
}
typeNameToAssemblyMap [ fullName ] = new TypeMetadata ( strongAssemblyName , isTypeObsolete ) ;
2016-04-06 21:01:07 +02:00
}
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
else if ( printDebugMessage )
2016-04-06 21:01:07 +02:00
{
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
// Duplicate types found defined in different assemblies, and fall into one of the following conditions:
// - both are obsolete
// - both are not obsolete
// - the existing type is not obsolete while the new one is obsolete
var existingTypeMetadata = typeNameToAssemblyMap [ fullName ] ;
Console . WriteLine ( $ @ "
DUPLICATE key ' { fullName } ' from ' { strongAssemblyName } ' ( IsObsolete ? { isTypeObsolete } ) .
- - Already exist in ' { existingTypeMetadata . AssemblyName } ' ( IsObsolete ? { existingTypeMetadata . IsObsolete } ) ");
2016-04-06 21:01:07 +02:00
}
2016-03-30 23:20:52 +02:00
}
}
}
2016-06-28 18:59:22 +02:00
WritePowerShellAssemblyLoadContextPartialClass ( targetFilePath , typeNameToAssemblyMap ) ;
2016-03-30 23:20:52 +02:00
}
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
/// <summary>
/// Check if the type is obsolete.
/// </summary>
private static bool IsTypeObsolete ( MetadataReader reader , TypeDefinition typeDefinition )
{
const string obsoleteFullTypeName = "System.ObsoleteAttribute" ;
foreach ( var customAttributeHandle in typeDefinition . GetCustomAttributes ( ) )
{
var customAttribute = reader . GetCustomAttribute ( customAttributeHandle ) ;
if ( IsAttributeOfType ( reader , customAttribute , obsoleteFullTypeName ) )
{
return true ;
}
}
return false ;
}
/// <summary>
/// Check if the attribute type name is what we expected.
/// </summary>
private static bool IsAttributeOfType ( MetadataReader reader , CustomAttribute customAttribute , string expectedTypeName )
{
string attributeFullName = null ;
switch ( customAttribute . Constructor . Kind )
{
case HandleKind . MethodDefinition :
// Attribute is defined in the same module
MethodDefinition methodDef = reader . GetMethodDefinition ( ( MethodDefinitionHandle ) customAttribute . Constructor ) ;
TypeDefinitionHandle declaringTypeDefHandle = methodDef . GetDeclaringType ( ) ;
if ( declaringTypeDefHandle . IsNil ) { /* Global method */ return false ; }
TypeDefinition declaringTypeDef = reader . GetTypeDefinition ( declaringTypeDefHandle ) ;
attributeFullName = GetTypeFullName ( reader , declaringTypeDef ) ;
break ;
case HandleKind . MemberReference :
MemberReference memberRef = reader . GetMemberReference ( ( MemberReferenceHandle ) customAttribute . Constructor ) ;
switch ( memberRef . Parent . Kind )
{
case HandleKind . TypeReference :
TypeReference typeRef = reader . GetTypeReference ( ( TypeReferenceHandle ) memberRef . Parent ) ;
attributeFullName = GetTypeFullName ( reader , typeRef ) ;
break ;
case HandleKind . TypeDefinition :
TypeDefinition typeDef = reader . GetTypeDefinition ( ( TypeDefinitionHandle ) memberRef . Parent ) ;
attributeFullName = GetTypeFullName ( reader , typeDef ) ;
break ;
default :
// constructor is global method, vararg method, or from a generic type.
return false ;
}
break ;
default :
throw new BadImageFormatException ( "Invalid custom attribute." ) ;
}
return string . Equals ( attributeFullName , expectedTypeName , StringComparison . Ordinal ) ;
}
2016-03-30 23:20:52 +02:00
/// <summary>
/// Get the strong name of a reference assembly represented by the 'metadataReader'
/// </summary>
private static string GetAssemblyStrongName ( MetadataReader metadataReader )
{
AssemblyDefinition assemblyDefinition = metadataReader . GetAssemblyDefinition ( ) ;
string asmName = metadataReader . GetString ( assemblyDefinition . Name ) ;
string asmVersion = assemblyDefinition . Version . ToString ( ) ;
string asmCulture = metadataReader . GetString ( assemblyDefinition . Culture ) ;
asmCulture = ( asmCulture = = string . Empty ) ? "neutral" : asmCulture ;
AssemblyHashAlgorithm hashAlgorithm = assemblyDefinition . HashAlgorithm ;
BlobHandle blobHandle = assemblyDefinition . PublicKey ;
BlobReader blobReader = metadataReader . GetBlobReader ( blobHandle ) ;
byte [ ] publickey = blobReader . ReadBytes ( blobReader . Length ) ;
HashAlgorithm hashImpl = null ;
switch ( hashAlgorithm )
{
case AssemblyHashAlgorithm . Sha1 :
2016-06-25 01:55:49 +02:00
hashImpl = SHA1 . Create ( ) ;
2016-03-30 23:20:52 +02:00
break ;
case AssemblyHashAlgorithm . MD5 :
2016-06-25 01:55:49 +02:00
hashImpl = MD5 . Create ( ) ;
2016-03-30 23:20:52 +02:00
break ;
case AssemblyHashAlgorithm . Sha256 :
2016-06-25 01:55:49 +02:00
hashImpl = SHA256 . Create ( ) ;
2016-03-30 23:20:52 +02:00
break ;
case AssemblyHashAlgorithm . Sha384 :
2016-06-25 01:55:49 +02:00
hashImpl = SHA384 . Create ( ) ;
2016-03-30 23:20:52 +02:00
break ;
case AssemblyHashAlgorithm . Sha512 :
2016-06-25 01:55:49 +02:00
hashImpl = SHA512 . Create ( ) ;
2016-03-30 23:20:52 +02:00
break ;
default :
throw new NotSupportedException ( ) ;
}
byte [ ] publicKeyHash = hashImpl . ComputeHash ( publickey ) ;
byte [ ] publicKeyTokenBytes = new byte [ 8 ] ;
// Note that, the low 8 bytes of the hash of public key in reverse order is the public key tokens.
for ( int i = 1 ; i < = 8 ; i + + )
{
publicKeyTokenBytes [ i - 1 ] = publicKeyHash [ publicKeyHash . Length - i ] ;
}
// Convert bytes to hex format strings in lower case.
string publicKeyTokenString = BitConverter . ToString ( publicKeyTokenBytes ) . Replace ( "-" , string . Empty ) . ToLowerInvariant ( ) ;
string strongAssemblyName = string . Format ( CultureInfo . InvariantCulture ,
"{0}, Version={1}, Culture={2}, PublicKeyToken={3}" ,
asmName , asmVersion , asmCulture , publicKeyTokenString ) ;
return strongAssemblyName ;
}
/// <summary>
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
/// Get the full name of a Type reference.
/// </summary>
private static string GetTypeFullName ( MetadataReader metadataReader , TypeReference typeReference )
{
string fullName ;
string typeName = metadataReader . GetString ( typeReference . Name ) ;
string nsName = metadataReader . GetString ( typeReference . Namespace ) ;
EntityHandle resolutionScope = typeReference . ResolutionScope ;
if ( resolutionScope . IsNil | | resolutionScope . Kind ! = HandleKind . TypeReference )
{
fullName = string . Format ( CultureInfo . InvariantCulture , Format_RegularType , nsName , typeName ) ;
}
else
{
// It's a nested type.
fullName = typeName ;
while ( ! resolutionScope . IsNil & & resolutionScope . Kind = = HandleKind . TypeReference )
{
TypeReference declaringTypeRef = metadataReader . GetTypeReference ( ( TypeReferenceHandle ) resolutionScope ) ;
resolutionScope = declaringTypeRef . ResolutionScope ;
if ( resolutionScope . IsNil | | resolutionScope . Kind ! = HandleKind . TypeReference )
{
fullName = string . Format ( CultureInfo . InvariantCulture , Format_SingleLevelNestedType ,
metadataReader . GetString ( declaringTypeRef . Namespace ) ,
metadataReader . GetString ( declaringTypeRef . Name ) ,
fullName ) ;
}
else
{
fullName = string . Format ( CultureInfo . InvariantCulture , Format_MultiLevelNestedType ,
metadataReader . GetString ( declaringTypeRef . Name ) ,
fullName ) ;
}
}
}
return fullName ;
}
/// <summary>
/// Get the full name of a Type definition.
2016-03-30 23:20:52 +02:00
/// </summary>
private static string GetTypeFullName ( MetadataReader metadataReader , TypeDefinition typeDefinition )
{
string fullName ;
string typeName = metadataReader . GetString ( typeDefinition . Name ) ;
string nsName = metadataReader . GetString ( typeDefinition . Namespace ) ;
// Get the enclosing type if the type is nested
TypeDefinitionHandle declaringTypeHandle = typeDefinition . GetDeclaringType ( ) ;
if ( declaringTypeHandle . IsNil )
{
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
fullName = string . Format ( CultureInfo . InvariantCulture , Format_RegularType , nsName , typeName ) ;
2016-03-30 23:20:52 +02:00
}
else
{
fullName = typeName ;
while ( ! declaringTypeHandle . IsNil )
{
TypeDefinition declaringTypeDef = metadataReader . GetTypeDefinition ( declaringTypeHandle ) ;
declaringTypeHandle = declaringTypeDef . GetDeclaringType ( ) ;
if ( declaringTypeHandle . IsNil )
{
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
fullName = string . Format ( CultureInfo . InvariantCulture , Format_SingleLevelNestedType ,
2016-03-30 23:20:52 +02:00
metadataReader . GetString ( declaringTypeDef . Namespace ) ,
metadataReader . GetString ( declaringTypeDef . Name ) ,
fullName ) ;
}
else
{
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
fullName = string . Format ( CultureInfo . InvariantCulture , Format_MultiLevelNestedType ,
2016-03-30 23:20:52 +02:00
metadataReader . GetString ( declaringTypeDef . Name ) ,
fullName ) ;
}
}
}
return fullName ;
}
/// <summary>
/// Resolve the target file path
/// </summary>
private static string ResolveTargetFilePath ( string path )
{
if ( string . IsNullOrWhiteSpace ( path ) )
{
throw new ArgumentNullException ( Param_TargetCSharpFilePath ) ;
}
string targetPath = Path . GetFullPath ( path ) ;
string targetParentFolder = Path . GetDirectoryName ( targetPath ) ;
if ( ! Directory . Exists ( targetParentFolder ) )
{
string message = string . Format ( CultureInfo . CurrentCulture , TargetSourceDirNotFound , targetParentFolder ? ? "null" ) ;
throw new ArgumentException ( message ) ;
}
return targetPath ;
}
/// <summary>
/// Resolve the reference assembly file paths
/// </summary>
private static List < string > ResolveReferenceAssemblies ( string path )
{
if ( string . IsNullOrWhiteSpace ( path ) )
{
throw new ArgumentNullException ( Param_ReferenceListPath ) ;
}
string referenceListPath = Path . GetFullPath ( path ) ;
if ( ! File . Exists ( referenceListPath ) )
{
string message = string . Format ( CultureInfo . CurrentCulture , ReferenceListFileNotFound , referenceListPath ? ? "null" ) ;
throw new ArgumentException ( message ) ;
}
string allText = File . ReadAllText ( referenceListPath ) ;
string [ ] references = allText . Split ( new char [ ] { ';' } , StringSplitOptions . RemoveEmptyEntries ) ;
List < string > refAssemblyFiles = new List < string > ( 120 ) ;
for ( int i = 0 ; i < references . Length ; i + + )
{
// Ignore entries that only contain white spaces
if ( string . IsNullOrWhiteSpace ( references [ i ] ) )
{
continue ;
}
string refAssemblyPath = references [ i ] . Trim ( ) ;
if ( File . Exists ( refAssemblyPath ) )
{
refAssemblyFiles . Add ( refAssemblyPath ) ;
}
else
{
string message = string . Format ( CultureInfo . CurrentCulture , RefAssemblyNotFound , refAssemblyPath , referenceListPath ) ;
throw new InvalidDataException ( message ) ;
}
}
return refAssemblyFiles ;
}
/// <summary>
/// Generate the CSharp source code that initialize the type catalog.
/// </summary>
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
private static void WritePowerShellAssemblyLoadContextPartialClass ( string targetFilePath , Dictionary < string , TypeMetadata > typeNameToAssemblyMap )
2016-03-30 23:20:52 +02:00
{
const string SourceFormat = " typeCatalog[\"{0}\"] = \"{1}\";" ;
const string SourceHead = @ "//
// This file is auto-generated by TypeCatalogGen.exe during build of Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll.
// This file will be compiled into Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll.
//
2017-01-16 22:31:14 +01:00
// In CoreCLR, there is no way to get all loaded TPA assemblies (.NET Framework Assemblies). In order to get type based on type
2016-03-30 23:20:52 +02:00
// name, powershell needs to know what .NET types are available and in which TPA assemblies. So we have to generate this type
// catalog based on the reference assemblies of .NET Core.
//
using System.Collections.Generic ;
2016-06-28 18:59:22 +02:00
using System.Runtime.Loader ;
2016-03-30 23:20:52 +02:00
namespace System.Management.Automation
{ {
2017-06-06 05:59:30 +02:00
internal partial class PowerShellAssemblyLoadContext
2016-03-30 23:20:52 +02:00
{ {
private Dictionary < string , string > InitializeTypeCatalog ( )
{ {
Dictionary < string , string > typeCatalog = new Dictionary < string , string > ( { 0 } , StringComparer . OrdinalIgnoreCase ) ;
";
const string SourceEnd = @ "
return typeCatalog ;
}
}
}
";
StringBuilder sourceCode = new StringBuilder ( string . Format ( CultureInfo . InvariantCulture , SourceHead , typeNameToAssemblyMap . Count ) ) ;
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
foreach ( KeyValuePair < string , TypeMetadata > pair in typeNameToAssemblyMap )
2016-03-30 23:20:52 +02:00
{
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
sourceCode . AppendLine ( string . Format ( CultureInfo . InvariantCulture , SourceFormat , pair . Key , pair . Value . AssemblyName ) ) ;
2016-03-30 23:20:52 +02:00
}
sourceCode . Append ( SourceEnd ) ;
using ( FileStream stream = new FileStream ( targetFilePath , FileMode . Create , FileAccess . Write ) )
using ( StreamWriter writer = new StreamWriter ( stream , Encoding . ASCII ) )
{
writer . Write ( sourceCode . ToString ( ) ) ;
}
}
Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 20:52:38 +02:00
/// <summary>
/// Helper class to keep the metadata of a type
/// </summary>
private class TypeMetadata
{
internal readonly string AssemblyName ;
internal readonly bool IsObsolete ;
internal TypeMetadata ( string assemblyName , bool isTypeObsolete )
{
this . AssemblyName = assemblyName ;
this . IsObsolete = isTypeObsolete ;
}
}
2016-03-30 23:20:52 +02:00
}
}