mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Merge pull request #1512 from PowerShell/vors/add-type
Add-Type: add mscorlib.dll to the list of default references
This commit is contained in:
commit
5402ba096a
3 files changed
+46
-12
No files matched your search
+9
-1
@@ -89,7 +89,15 @@ function Start-PSBuild {
|
||||
if ($Clean)
|
||||
{
|
||||
log "Cleaning your working directory. You can also do it with 'git clean -fdX'"
|
||||
git clean -fdX
|
||||
Push-Location $PSScriptRoot
|
||||
try
|
||||
{
|
||||
git clean -fdX
|
||||
}
|
||||
finally
|
||||
{
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
# save Git description to file for PowerShell to include in PSVersionTable
|
||||
|
||||
@@ -1059,24 +1059,37 @@ namespace Microsoft.PowerShell.Commands
|
||||
private static PortableExecutableReference ObjectImplementationAssemblyReference =
|
||||
MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location);
|
||||
|
||||
private static PortableExecutableReference MscorlibAssemblyReference =
|
||||
MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("mscorlib")).Location);
|
||||
|
||||
// This assembly should be System.Runtime.dll
|
||||
private static PortableExecutableReference ObjectDeclaredAssemblyReference =
|
||||
private static PortableExecutableReference SystemRuntimeAssemblyReference =
|
||||
MetadataReference.CreateFromFile(ClrFacade.GetAssemblies(typeof(object).FullName).First().Location);
|
||||
|
||||
// CoreCLR RC2 bits don't have SecureString. We are using a separate assembly with SecureString implementation.
|
||||
// SecureString is defined in a separate assembly.
|
||||
// This fact is an implementation detail and should not require the user to specify one more assembly,
|
||||
// if they want to use SecureString in Add-Type -TypeDefinition.
|
||||
// So this assembly should be in the default assemblies list to provide the best experience.
|
||||
//
|
||||
// TODO: This reference should be removed, if we take CoreCLR version that has SecureString implementation.
|
||||
private static PortableExecutableReference SecureStringAssemblyReference =
|
||||
MetadataReference.CreateFromFile(typeof(System.Security.SecureString).GetTypeInfo().Assembly.Location);
|
||||
|
||||
private static MetadataReference[] defaultAssemblies = new MetadataReference[]
|
||||
|
||||
// These assemlbies are always automatically added to ReferencedAssemblies.
|
||||
private static PortableExecutableReference[] autoReferencedAssemblies = new PortableExecutableReference[]
|
||||
{
|
||||
ObjectImplementationAssemblyReference,
|
||||
ObjectDeclaredAssemblyReference,
|
||||
MscorlibAssemblyReference,
|
||||
SystemRuntimeAssemblyReference,
|
||||
SecureStringAssemblyReference,
|
||||
ObjectImplementationAssemblyReference
|
||||
};
|
||||
|
||||
// These assemlbies are used, when ReferencedAssemblies parameter is not specified.
|
||||
private static PortableExecutableReference[] defaultAssemblies = new PortableExecutableReference[]
|
||||
{
|
||||
MscorlibAssemblyReference,
|
||||
SystemRuntimeAssemblyReference,
|
||||
SecureStringAssemblyReference,
|
||||
ObjectImplementationAssemblyReference,
|
||||
MetadataReference.CreateFromFile(typeof(PSObject).GetTypeInfo().Assembly.Location)
|
||||
};
|
||||
|
||||
@@ -1218,9 +1231,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (referencedAssembliesSpecified)
|
||||
{
|
||||
var tempReferences = ReferencedAssemblies.Select(a => MetadataReference.CreateFromFile(ResolveReferencedAssembly(a))).ToList();
|
||||
tempReferences.Add(ObjectImplementationAssemblyReference);
|
||||
tempReferences.Add(ObjectDeclaredAssemblyReference);
|
||||
tempReferences.Add(SecureStringAssemblyReference);
|
||||
tempReferences.AddRange(autoReferencedAssemblies);
|
||||
|
||||
references = tempReferences.ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
$guid = [Guid]::NewGuid().ToString().Replace("-","")
|
||||
|
||||
Describe "Add-Type" {
|
||||
It "Should not throw given a simple class definition" {
|
||||
{ Add-Type -TypeDefinition "public static class foo { }" } | Should Not Throw
|
||||
{ Add-Type -TypeDefinition "public static class foo { }" } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Can use System.Management.Automation.CmdletAttribute" {
|
||||
$code = @"
|
||||
[System.Management.Automation.Cmdlet("Get", "Thing", ConfirmImpact = System.Management.Automation.ConfirmImpact.High, SupportsPaging = true)]
|
||||
public class AttributeTest$guid {}
|
||||
"@
|
||||
Add-Type -TypeDefinition $code -PassThru | Should Not Be $null
|
||||
}
|
||||
|
||||
It "Can load TPA assembly System.Runtime.Serialization.Primitives.dll" {
|
||||
Add-Type -AssemblyName 'System.Runtime.Serialization.Primitives' -PassThru | Should Not Be $null
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user