Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,4 @@
<data name="LoadSystemSnapinAsModule" xml:space="preserve">
<value>Cannot add PowerShell snap-in {0} because it is a system PowerShell module. Use Import-Module to load the module.</value>
</data>
<data name="CustomPSSnapInNotSupportedInPowerShellCore" xml:space="preserve">
<value>The custom PowerShell snap-in is not supported in PowerShell Core.</value>
</data>
</root>
112 changes: 60 additions & 52 deletions src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.Win32;
using System.Security;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using System.Globalization;
using Regex = System.Text.RegularExpressions.Regex;
using System.Security;

using Dbg = System.Management.Automation.Diagnostics;
using Microsoft.PowerShell.Commands;
using Microsoft.Win32;

using Dbg = System.Management.Automation.Diagnostics;
using Regex = System.Text.RegularExpressions.Regex;

namespace System.Management.Automation
{
Expand Down Expand Up @@ -50,7 +51,6 @@ internal static class RegistryStrings
internal const string MshSnapin_AssemblyName = "AssemblyName";
internal const string MshSnapin_ModuleName = "ModuleName";
internal const string MshSnapin_MonadVersion = "PowerShellVersion";
internal const string MshSnapin_CustomPSSnapInType = "CustomPSSnapInType";
internal const string MshSnapin_BuiltInTypes = "Types";
internal const string MshSnapin_BuiltInFormats = "Formats";
internal const string MshSnapin_Description = "Description";
Expand Down Expand Up @@ -85,8 +85,7 @@ internal PSSnapInInfo
Collection<string> types,
Collection<string> formats,
string descriptionFallback,
string vendorFallback,
string customPSSnapInType
string vendorFallback
)
{
if (string.IsNullOrEmpty(name))
Expand Down Expand Up @@ -114,16 +113,6 @@ string customPSSnapInType
throw PSTraceSource.NewArgumentNullException("psVersion");
}

#if CORECLR // CustomPSSnapIn Not Supported On CSS.
// CustomPSSnapIn derives from System.Configuration.Install, which is not in CoreCLR.
if (customPSSnapInType != null)
{
throw PSTraceSource.NewArgumentException(
"customPSSnapInType",
MshSnapInCmdletResources.CustomPSSnapInNotSupportedInPowerShellCore);
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this resource string from the .resx file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

}
#endif

if (version == null)
{
version = new Version("0.0");
Expand Down Expand Up @@ -158,7 +147,6 @@ string customPSSnapInType
Version = version;
Types = types;
Formats = formats;
CustomPSSnapInType = customPSSnapInType;
_descriptionFallback = descriptionFallback;
_vendorFallback = vendorFallback;
}
Expand All @@ -177,10 +165,9 @@ internal PSSnapInInfo
string description,
string descriptionFallback,
string vendor,
string vendorFallback,
string customPSSnapInType
string vendorFallback
)
: this(name, isDefault, applicationBase, assemblyName, moduleName, psVersion, version, types, formats, descriptionFallback, vendorFallback, customPSSnapInType)
: this(name, isDefault, applicationBase, assemblyName, moduleName, psVersion, version, types, formats, descriptionFallback, vendorFallback)
{
_description = description;
_vendor = vendor;
Expand All @@ -202,9 +189,8 @@ internal PSSnapInInfo
string descriptionIndirect,
string vendor,
string vendorFallback,
string vendorIndirect,
string customPSSnapInType
) : this(name, isDefault, applicationBase, assemblyName, moduleName, psVersion, version, types, formats, description, descriptionFallback, vendor, vendorFallback, customPSSnapInType)
string vendorIndirect
) : this(name, isDefault, applicationBase, assemblyName, moduleName, psVersion, version, types, formats, description, descriptionFallback, vendor, vendorFallback)
{
// add descriptionIndirect and vendorIndirect only if the mshsnapin is a default mshsnapin
if (isDefault)
Expand Down Expand Up @@ -256,11 +242,6 @@ internal string AbsoluteModulePath
}
}

/// <summary>
/// Type of custom mshsnapin.
/// </summary>
internal string CustomPSSnapInType { get; }

/// <summary>
/// Monad version used by mshsnapin
/// </summary>
Expand Down Expand Up @@ -414,13 +395,22 @@ internal void LoadIndirectResources(RegistryStringResourceIndirect resourceReade

internal PSSnapInInfo Clone()
{
PSSnapInInfo cloned = new PSSnapInInfo(Name,
IsDefault, ApplicationBase, AssemblyName,
ModuleName, PSVersion, Version, new Collection<string>(Types),
new Collection<string>(Formats), _description,
_descriptionFallback, _descriptionIndirect, _vendor, _vendorFallback, _vendorIndirect,
CustomPSSnapInType
);
PSSnapInInfo cloned = new PSSnapInInfo(
Name,
IsDefault,
ApplicationBase,
AssemblyName,
ModuleName,
PSVersion,
Version,
new Collection<string>(Types),
new Collection<string>(Formats),
_description,
_descriptionFallback,
_descriptionIndirect,
_vendor,
_vendorFallback,
_vendorIndirect);

return cloned;
}
Expand Down Expand Up @@ -728,17 +718,11 @@ private static PSSnapInInfo ReadOne(RegistryKey mshSnapInRoot, string mshsnapinI
logPipelineExecutionDetails = true;
}

string customPSSnapInType = ReadStringValue(mshsnapinKey, RegistryStrings.MshSnapin_CustomPSSnapInType, false);
if (string.IsNullOrEmpty(customPSSnapInType))
{
customPSSnapInType = null;
}

Collection<string> types = ReadMultiStringValue(mshsnapinKey, RegistryStrings.MshSnapin_BuiltInTypes, false);
Collection<string> formats = ReadMultiStringValue(mshsnapinKey, RegistryStrings.MshSnapin_BuiltInFormats, false);

s_mshsnapinTracer.WriteLine("Successfully read registry values for mshsnapin {0}. Constructing PSSnapInInfo object.", mshsnapinId);
PSSnapInInfo mshSnapinInfo = new PSSnapInInfo(mshsnapinId, false, applicationBase, assemblyName, moduleName, monadVersion, version, types, formats, description, vendor, customPSSnapInType);
PSSnapInInfo mshSnapinInfo = new PSSnapInInfo(mshsnapinId, false, applicationBase, assemblyName, moduleName, monadVersion, version, types, formats, description, vendor);
mshSnapinInfo.LogPipelineExecutionDetails = logPipelineExecutionDetails;

return mshSnapinInfo;
Expand Down Expand Up @@ -963,10 +947,22 @@ internal static PSSnapInInfo ReadCoreEngineSnapIn()

string moduleName = Path.Combine(applicationBase, s_coreSnapin.AssemblyName + ".dll");

PSSnapInInfo coreMshSnapin = new PSSnapInInfo(s_coreSnapin.PSSnapInName, true, applicationBase,
strongName, moduleName, psVersion, assemblyVersion, types, formats, null,
s_coreSnapin.Description, s_coreSnapin.DescriptionIndirect, null, null,
s_coreSnapin.VendorIndirect, null);
PSSnapInInfo coreMshSnapin = new PSSnapInInfo(
s_coreSnapin.PSSnapInName,
isDefault: true,
applicationBase,
strongName,
moduleName,
psVersion,
assemblyVersion,
types,
formats,
description: null,
s_coreSnapin.Description,
s_coreSnapin.DescriptionIndirect,
vendor: null,
vendorFallback: null,
s_coreSnapin.VendorIndirect);
#if !UNIX
// NOTE: On Unix, logging has to be deferred until after command-line parsing
// complete. On Windows, deferring the call is not needed
Expand Down Expand Up @@ -1040,10 +1036,22 @@ internal static Collection<PSSnapInInfo> ReadEnginePSSnapIns()
moduleName = defaultMshSnapinInfo.AssemblyName;
}

PSSnapInInfo defaultMshSnapin = new PSSnapInInfo(defaultMshSnapinInfo.PSSnapInName, true, applicationBase,
strongName, moduleName, psVersion, assemblyVersion, types, formats, null,
defaultMshSnapinInfo.Description, defaultMshSnapinInfo.DescriptionIndirect, null, null,
defaultMshSnapinInfo.VendorIndirect, null);
PSSnapInInfo defaultMshSnapin = new PSSnapInInfo(
defaultMshSnapinInfo.PSSnapInName,
isDefault: true,
applicationBase,
strongName,
moduleName,
psVersion,
assemblyVersion,
types,
formats,
description: null,
defaultMshSnapinInfo.Description,
defaultMshSnapinInfo.DescriptionIndirect,
vendor: null,
vendorFallback: null,
defaultMshSnapinInfo.VendorIndirect);

SetSnapInLoggingInformation(defaultMshSnapin);
engineMshSnapins.Add(defaultMshSnapin);
Expand Down