Skip to content

Conversation

@daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Apr 13, 2017

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. Note that the -cache option is removed from appveyor.yml, but it probably should be added back after this PR is merged. The -cache section is added back and specified to depend on appveyor.yml, so the cache will be invalidated if appveyor.yml is changed. Thanks to @TravisEz13
  4. Ship netcoreapp reference assemblies with powershell to fix the issues in Add-Type (Add-Type failed to create a type that implements IWebProxy #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 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. When moving to newer version of netcoreapp2.0, we need to verify if this dependency is still needed.

appveyor.yml Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to cache these at all?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we clear the cache with a REST call instead of this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a language to describe when to clear the cache https://www.appveyor.com/docs/build-cache/#cache-dependencies

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the description:

Note that the -cache option is removed from appveyor.yml, but it probably should be added back after this PR is merged.

I planned to added it back after this PR gets merged, and add one more directory path: %HOMEDRIVE%%HOMEPATH%\.dotnet. dotnet-cli 2.0.0 depends on such a folder now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TravisEz13 talked to me offline and it turns out it's quite easy to invalidate the cache, I will do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment would be nice - because 1000 seems like a more reasonable value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good or useful test - a better test would sample for some expected members.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the test to sample for 3 members: a, CreateNode, CreateElement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably shouldn't delete !CORECLR code in the PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is added back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought registry apis would throw on Unix - so why is this changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SafeRegistryHandle is used for transactioned registry, which is not enabled in powershell core. Actually the file SafeRegistryHandle.cs should be excluded from building powershell core.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this deleted? If it's Windows PowerShell only now - it should be a different PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, you just moved this type, but it's hard to see that for sure. Can it stay in the same place to make it easier to see if anything changed - and if it should move, do that in another refactoring PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I make this an exception? DataRow/DataRowView adapters were enabled in MshObject.cs when I was working on the first cut of refactoring to enable the build. ExtraAdapter.cs contains the adapters that are not supported in powershell core and is excluded from the build, that's why I moved those 2 adapters to CoreAdatper.cs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I will revert this change, as I didn't add any tests for the DataRow/DataRowView adapters anyway.

Copy link
Contributor

@lzybkr lzybkr Apr 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this code just moved files too? Again, it's hard to tell, and reviewing this for the first time, some of it is weird, like ProgramFiles is /bin, but ProgramFilesX86 is /sur/bin. Weird.

Copy link
Member Author

@daxian-dbw daxian-dbw Apr 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is moved from System.Management.Automation.Environment to SMA.Platform because the former class is completely removed because all environment members we extended now come back in System.Environment. Maybe we need to open a bug to review all if/defs and Unix specific code? -- #3565 is opened.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

predicted [](start = 16, length = 9)

predictable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@lzybkr
Copy link
Contributor

lzybkr commented Apr 14, 2017

@vors - can you review AddType.cs?

@daxian-dbw
Copy link
Member Author

@TravisEz13 @lzybkr @vors comments have been addressed, could you please continue the review? Thanks!

Copy link
Collaborator

@vors vors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is soooo good! 🎉

I'm signing up mostly on the Add-Type changes with minor comments.

}

# add 'x' permission when building the standalone application
# this is temporary workaround to a bug in dotnet.exe, tracking by dotnet/cli issue #6286
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a pretty hilarious bug


image: Visual Studio 2015

# cache version - netcoreapp.2.0.0-preview1-001913-00
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be '005724' ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

005724 is the build of dotnet-cli we are currently using, but the netcoreapp version is actually 2.0.0-preview1-001913-00.


// We look up in reference/framework only when it's for resolving reference assemblies.
// In case of 'Add-Type -AssemblyName' scenario, we don't attempt to resolve against framework assemblies because
// 2. Explicitly loading a framework assembly usually is not necessary in PowerShell Core.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@daxian-dbw daxian-dbw Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Will fix.

/// </summary>
private static PortableExecutableReference[] InitDefaultRefAssemblies()
{
var defaultRefAssemblies = new List<PortableExecutableReference>(150);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this hardcoded value. Maybe just leave it to a default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, netcoreapp2.0 comes with 137 reference assemblies, and that's why I choose 150 as the default value. I will add a comment.
By default, the capacity of List is 0, and it increases the size as you add more items. So if the size is roughly known, it's better to specify.


// Ignore some specified reference assemblies
string fileName = PathType.GetFileName(resolvedAssemblyPath);
if (s_refAssemblyNamesToIgnore.Value.Contains(fileName)) { continue; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add WriteVerbose() here about the ignoring the file names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add it.

<PackageReference Include="System.ServiceModel.Security" Version="4.4.0-beta-25205-01" />
<PackageReference Include="System.Text.Encodings.Web" Version="4.4.0-preview1-25204-02" />
<PackageReference Include="System.Threading.AccessControl" Version="4.4.0-preview1-25204-02" />
<PackageReference Include="System.Private.ServiceModel" Version="4.4.0-beta-25205-01" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double check that?
As we mentioned in https://github.com/PowerShell/PowerShell/tree/master/src/Microsoft.PowerShell.SDK

This second set includes packages that we do not necessarily require at compile-time, but must provide for our users at runtime. For example, we include the library System.Runtime.Serialization.Json.dll so that users of PowerShell can utilize its types and methods, even though PowerShell does not directly depend on the library.

I don't know much about the netstandart 2.0 model, but it's suspicious that we removing so many of them.
This list should be our SDK surface (subset of dotnet that we are promising to all applications).
It should not rely on our cross dependencies in the project.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

netcoreapp2.0 now includes most of those dependencies by default, and that's why many get removed from SDK.csproj. Now I'm inclined to use SDK.csproj as:

  1. meta project that references other projects
  2. meta project that references those packages that are not directly depended by powershell projects.

@daxian-dbw daxian-dbw merged commit 7a55bf9 into PowerShell:master Apr 17, 2017
@daxian-dbw
Copy link
Member Author

@TravisEz13 @vors @lzybkr Thanks for the review!

@iSazonov
Copy link
Collaborator

@daxian-dbw Great work! Thanks!

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

Successfully merging this pull request may close these issues.

6 participants