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 @@ -366,7 +366,7 @@ internal bool UseFullLanguageModeInDebugger
};

/// <summary>
/// Is true the PSScheduledJob and PSWorkflow modules are loaded for this runspace
/// Is true if the PSScheduledJob module is loaded for this runspace
/// </summary>
internal bool IsModuleWithJobSourceAdapterLoaded
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Microsoft.PowerShell.Commands
[Cmdlet(VerbsCommon.Get, "Command", DefaultParameterSetName = "CmdletSet", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113309")]
[OutputType(typeof(AliasInfo), typeof(ApplicationInfo), typeof(FunctionInfo),
typeof(CmdletInfo), typeof(ExternalScriptInfo), typeof(FilterInfo),
typeof(WorkflowInfo), typeof(string), typeof(PSObject))]
typeof(string), typeof(PSObject))]
public sealed class GetCommandCommand : PSCmdlet
{
#region Definitions of cmdlet parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ internal static ConcurrentDictionary<string, CommandTypes> GetExportedCommands(s
{
result = AnalyzeCdxmlModule(modulePath, context, lastWriteTime);
}
else if (extension.Equals(StringLiterals.WorkflowFileExtension, StringComparison.OrdinalIgnoreCase))
{
result = AnalyzeXamlModule(modulePath, context, lastWriteTime);
}
else if (extension.Equals(".dll", StringComparison.OrdinalIgnoreCase))
{
result = AnalyzeDllModule(modulePath, context, lastWriteTime);
Expand Down Expand Up @@ -366,11 +362,6 @@ private static ConcurrentDictionary<string, CommandTypes> AnalyzeScriptModule(st
return result;
}

private static ConcurrentDictionary<string, CommandTypes> AnalyzeXamlModule(string modulePath, ExecutionContext context, DateTime lastWriteTime)
{
return AnalyzeTheOldWay(modulePath, context, lastWriteTime);
}

private static ConcurrentDictionary<string, CommandTypes> AnalyzeCdxmlModule(string modulePath, ExecutionContext context, DateTime lastWriteTime)
{
return AnalyzeTheOldWay(modulePath, context, lastWriteTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,6 @@ private PSModuleInfo ImportModule_LocallyViaName(ImportModuleOptions importModul
{
try
{
if (name.Equals("PSWorkflow", StringComparison.OrdinalIgnoreCase) && Utils.IsRunningFromSysWOW64())
{
throw new NotSupportedException(AutomationExceptions.WorkflowDoesNotSupportWOW64);
}

bool found = false;
PSModuleInfo foundModule = null;

Expand Down
587 changes: 66 additions & 521 deletions src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs

Large diffs are not rendered by default.

94 changes: 10 additions & 84 deletions src/System.Management.Automation/engine/Modules/PSModuleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -575,31 +575,21 @@ public ReadOnlyDictionary<string, TypeDefinitionAst> GetExportedTypeDefinitions(
}

var res = new Dictionary<string, TypeDefinitionAst>(StringComparer.OrdinalIgnoreCase);
if (this.NestedModules != null)
foreach (var nestedModule in this.NestedModules)
{
foreach (var nestedModule in this.NestedModules)
{
if (nestedModule == this)
{
// this is totally bizzare, but it happens for some reasons for
// Microsoft.Powershell.Workflow.ServiceCore.dll, when there is a workflow defined in a nested module.
// TODO(sevoroby): we should handle possible circular dependencies
continue;
}

foreach (var typePairs in nestedModule.GetExportedTypeDefinitions())
{
// The last one name wins! It's the same for command names in nested modules.
// For rootModule C with Two nested modules (A, B) the order is: A, B, C
res[typePairs.Key] = typePairs.Value;
}
}
foreach (var typePairs in _exportedTypeDefinitionsNoNested)
foreach (var typePairs in nestedModule.GetExportedTypeDefinitions())
{
// The last one name wins! It's the same for command names in nested modules.
// For rootModule C with Two nested modules (A, B) the order is: A, B, C
res[typePairs.Key] = typePairs.Value;
}
}

foreach (var typePairs in _exportedTypeDefinitionsNoNested)
{
res[typePairs.Key] = typePairs.Value;
}

return new ReadOnlyDictionary<string, TypeDefinitionAst>(res);
}

Expand Down Expand Up @@ -640,8 +630,6 @@ public String Prefix
internal Collection<string> DeclaredFunctionExports = null;
internal List<string> _detectedFunctionExports = new List<string>();

internal List<string> _detectedWorkflowExports = new List<string>();

/// <summary>
/// Add function to the fixed exports list
/// </summary>
Expand All @@ -656,20 +644,6 @@ internal void AddDetectedFunctionExport(string name)
}
}

/// <summary>
/// Add workflow to the fixed exports list
/// </summary>
/// <param name="name">the function to add</param>
internal void AddDetectedWorkflowExport(string name)
{
Dbg.Assert(name != null, "AddDetectedWorkflowExport should not be called with a null value");

if (!_detectedWorkflowExports.Contains(name))
{
_detectedWorkflowExports.Add(name);
}
}

/// <summary>
/// Lists the functions exported by this module...
/// </summary>
Expand Down Expand Up @@ -759,15 +733,6 @@ public Dictionary<string, CommandInfo> ExportedCommands
}
}

Dictionary<string, FunctionInfo> workflows = this.ExportedWorkflows;
if (workflows != null)
{
foreach (var workflow in workflows)
{
exports[workflow.Key] = workflow.Value;
}
}

Dictionary<string, AliasInfo> aliases = this.ExportedAliases;
if (aliases != null)
{
Expand Down Expand Up @@ -1177,48 +1142,9 @@ public Dictionary<string, FunctionInfo> ExportedWorkflows
{
get
{
Dictionary<string, FunctionInfo> exportedWorkflows = new Dictionary<string, FunctionInfo>(StringComparer.OrdinalIgnoreCase);

if ((DeclaredWorkflowExports != null) && (DeclaredWorkflowExports.Count > 0))
{
foreach (string fn in DeclaredWorkflowExports)
{
WorkflowInfo tempWf = new WorkflowInfo(fn, ScriptBlock.EmptyScriptBlock, context: null) { Module = this };
exportedWorkflows[fn] = tempWf;
}
}
if ((DeclaredWorkflowExports != null) && (DeclaredWorkflowExports.Count == 0))
{
return exportedWorkflows;
}
else
{
// If there is no session state object associated with this list,
// just return a null list of exports. This will be true if the
// module is a compiled module.
if (SessionState == null)
{
foreach (string detectedExport in _detectedWorkflowExports)
{
if (!exportedWorkflows.ContainsKey(detectedExport))
{
WorkflowInfo tempWf = new WorkflowInfo(detectedExport, ScriptBlock.EmptyScriptBlock, context: null) { Module = this };
exportedWorkflows[detectedExport] = tempWf;
}
}
return exportedWorkflows;
}

foreach (WorkflowInfo wi in SessionState.Internal.ExportedWorkflows)
{
exportedWorkflows[wi.Name] = wi;
}
}

return exportedWorkflows;
return new Dictionary<string, FunctionInfo>(StringComparer.OrdinalIgnoreCase);
}
}
internal Collection<string> DeclaredWorkflowExports = null;

/// <summary>
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ private void GetModulePaths(CommandInfo commandInfo, out string moduleName, out
}
else if (scriptCommandInfo != null &&
(nestedModule.ExportedFunctions.ContainsKey(commandInfo.Name) ||
nestedModule.ExportedWorkflows.ContainsKey(commandInfo.Name) ||
(testWithoutPrefix && nestedModule.ExportedFunctions.ContainsKey(cmdNameWithoutPrefix)) ||
(testWithoutPrefix && nestedModule.ExportedWorkflows.ContainsKey(cmdNameWithoutPrefix))))
(testWithoutPrefix && nestedModule.ExportedFunctions.ContainsKey(cmdNameWithoutPrefix))))
{
nestedModulePath = nestedModule.Path;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@
<data name="CantConvertPipelineStartsWithExpression" xml:space="preserve">
<value>Cannot generate a PowerShell object for a ScriptBlock that starts a pipeline with an expression.</value>
</data>
<data name="WorkflowDoesNotSupportWOW64" xml:space="preserve">
<value>Windows PowerShell Workflow is not supported in a Windows PowerShell x86-based console. Open a Windows PowerShell x64-based console, and then try again.</value>
</data>
<data name="UsingVariableIsUndefined" xml:space="preserve">
<value>The value of the using variable '$using:{0}' cannot be retrieved because it has not been set in the local session.</value>
</data>
Expand Down
26 changes: 1 addition & 25 deletions src/System.Management.Automation/resources/Modules.resx
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,6 @@
<data name="VariablesToExport" xml:space="preserve">
<value>Variables to export from this module</value>
</data>
<data name="WorkflowsToExport" xml:space="preserve">
<value>Commands to export from this module as workflows</value>
</data>
<data name="DscResourcesToExport" xml:space="preserve">
<value>DSC resources to export from this module</value>
</data>
Expand All @@ -480,9 +477,6 @@
<data name="PowerShellHostVersion" xml:space="preserve">
<value>Minimum version of the PowerShell host required by this module</value>
</data>
<data name="LoadingWorkflow" xml:space="preserve">
<value>Loading workflow {0}</value>
</data>
<data name="HelpInfoURI" xml:space="preserve">
<value>HelpInfo URI of this module</value>
</data>
Expand All @@ -495,9 +489,6 @@
<data name="ModuleDriveInUse" xml:space="preserve">
<value>Because the {0} module is providing the PSDrive in the current PowerShell session, no modules were removed. Change the current PSDrive provider, and then try removing modules again.</value>
</data>
<data name="InvalidWorkflowExtensionDuringManifestProcessing" xml:space="preserve">
<value>The workflow file name extension is not valid. The workflow file name {0} that is listed in the WorkflowsToProcess key of the module manifest does not have the required .XAML or .DLL file name extension. Edit the module manifest and correct the workflow file name. If you are using a .DLL file extension, then provide only one assembly name.</value>
</data>
<data name="ImportModuleNoClobberForCmdlet" xml:space="preserve">
<value>The cmdlet '{0}' was not imported because there is a member with the same name in the current scope.</value>
</data>
Expand Down Expand Up @@ -546,27 +537,15 @@
<data name="RemoteDiscoveryWorksOnlyInListAvailableMode" xml:space="preserve">
<value>Running the Get-Module cmdlet against a remote computer can only list available modules. Add the ListAvailable parameter to your command, and then try again.</value>
</data>
<data name="ExportAsWorkflowInvalidCommand" xml:space="preserve">
<value>The command cannot be exported as workflow '{0}'.</value>
</data>
<data name="ExportingWorkflow" xml:space="preserve">
<value>Exporting workflow '{0}'.</value>
</data>
<data name="ImportingWorkflow" xml:space="preserve">
<value>Importing command as workflow '{0}'.</value>
</data>
<data name="ImportModuleNoClobberForWorkflow" xml:space="preserve">
<value>The command '{0}' was not imported as a workflow because there is a member with the same name in the current scope.</value>
</data>
<data name="ModuleLoadedAsASnapin" xml:space="preserve">
<value>The '{0}' module was not imported because the '{0}' snap-in was already imported.</value>
</data>
<data name="WildCardNotAllowedInRequiredAssemblies" xml:space="preserve">
<value>Wildcard characters are not allowed in the member 'RequiredAssemblies' in the module manifest '{0}'.</value>
</data>
<data name="ExportingCommandAsWorkflow" xml:space="preserve">
<value>Exporting command as workflow '{0}'.</value>
</data>
<data name="CmdletizationDoesSupportRexportingNestedModules" xml:space="preserve">
<value>The value of the {0} key in {1} is {2} and the module has nested modules. When a CDXML file is the root module, the Import-Module command fails because the commands in nested modules cannot be exported. Move the CDXML file to the NestedModules key and try the command again.</value>
<comment>{0} is equal to either ModuleToProcess or RootModule
Expand All @@ -592,9 +571,6 @@
<value>A CIM provider for module discovery was not found on the CIM server. {0}</value>
<comment>{0} is a placeholder for a more detailed error message</comment>
</data>
<data name="XamlWorkflowsNotSupported" xml:space="preserve">
<value>Cannot load the workflow. Only signed in-box XAML-based workflows or script-based workflows are supported in the current language mode.</value>
</data>
<data name="CannotDetectNetFrameworkVersion" xml:space="preserve">
<value>Cannot verify the Microsoft .NET Framework version {0} because it is not included in the list of permitted versions.</value>
</data>
Expand All @@ -621,7 +597,7 @@
<data name="ModuleNotFoundForGetModule" xml:space="preserve">
<value>The specified module '{0}' was not found. Update the Name parameter to point to a valid path, and then try again. </value>
</data>
<data name="WorkflowModuleNotSupportedInPowerShellCore" xml:space="preserve">
<data name="WorkflowModuleNotSupported" xml:space="preserve">
<value>Cannot load the workflow module '{0}'. Workflow is not supported in PowerShell Core.</value>
</data>
<data name="PopulatingRepositorySourceLocation" xml:space="preserve">
Expand Down
4 changes: 0 additions & 4 deletions src/System.Management.Automation/utils/PsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ internal static uint GetNativeThreadId()

private static class NativeMethods
{
// Important:
// this clone has a clone in SMA in admin\monad\src\m3p\product\ServiceCore\WorkflowCore\WorkflowRuntimeCompilation.cs
// if you are making any changes specific to this class then update the clone as well.

internal const ushort PROCESSOR_ARCHITECTURE_INTEL = 0;
internal const ushort PROCESSOR_ARCHITECTURE_ARM = 5;
internal const ushort PROCESSOR_ARCHITECTURE_IA64 = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace ModuleCmdlets

$psdFile = Join-Path $TESTDRIVE test.psd1
$nestedModule = Join-Path NOExistedPath Microsoft.PowerShell.Commands.Utility.dll
New-ModuleManifest -Path $psdFile -NestedModules $nestedModule
New-ModuleManifest -Path $psdFile -NestedModules $nestedModule
try
{
$module = Import-Module $psdFile -PassThru
Expand All @@ -158,7 +158,7 @@ namespace ModuleCmdlets
{
Remove-Module $module -ErrorAction SilentlyContinue
}

}
}

Expand Down Expand Up @@ -200,3 +200,34 @@ Describe "Import-Module should be case insensitive" -Tags 'CI' {
Get-Module tESTmODULE | Should -BeNullOrEmpty
}
}

Describe "Workflow .Xaml module is not supported in PSCore" -tags "Feature" {
BeforeAll {
$xamlFile = Join-Path $TestDrive "XamlTest.xaml"
New-Item -Path $xamlFile -ItemType File -Force

$xamlRootModule = Join-Path $TestDrive "XamlRootModule"
New-Item -Path $xamlRootModule -ItemType Directory -Force
Copy-Item $xamlFile $xamlRootModule
$xamlRootModuleManifest = Join-Path $xamlRootModule "XamlRootModule.psd1"
New-ModuleManifest -Path $xamlRootModuleManifest -RootModule "XamlTest.xaml"

$xamlNestedModule = Join-Path $TestDrive "XamlNestedModule"
New-Item -Path $xamlNestedModule -ItemType Directory -Force
Copy-Item $xamlFile $xamlNestedModule
$xamlNestedModuleManifest = Join-Path $xamlNestedModule "XamlNestedModule.psd1"
New-ModuleManifest -Path $xamlNestedModuleManifest -NestedModules "XamlTest.xaml"
}

It "Import a XAML file directly should raise a 'NotSupported' error" {
{ Import-Module $xamlFile -ErrorAction Stop } | Should -Throw -ErrorId "Modules_WorkflowModuleNotSupported,Microsoft.PowerShell.Commands.ImportModuleCommand"
}

It "Import a module with XAML root module should raise a 'NotSupportd' error" {
{ Import-Module $xamlRootModule -ErrorAction Stop } | Should -Throw -ErrorId "Modules_WorkflowModuleNotSupported,Microsoft.PowerShell.Commands.ImportModuleCommand"
}

It "Import a module with XAML nested module should raise a 'NotSupported' error" {
{ Import-Module $xamlNestedModule -ErrorAction Stop } | Should -Throw -ErrorId "Modules_WorkflowModuleNotSupported,Microsoft.PowerShell.Commands.ImportModuleCommand"
}
}
4 changes: 2 additions & 2 deletions test/powershell/engine/Module/TestModuleManifest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Describe "Test-ModuleManifest tests" -tags "CI" {

It "module manifest containing valid processed empty rootmodule file type fails: <rootModuleValue>" -TestCases (
@{rootModuleValue = "foo.cdxml"; error = "System.Xml.XmlException"}, # fails when cmdlet tries to read it as XML
@{rootModuleValue = "foo.xaml"; error = "NotSupported"} # not supported on PowerShell Core
@{rootModuleValue = "foo.xaml"; error = "Modules_WorkflowModuleNotSupported"} # not supported on PowerShell Core
) {

param($rootModuleValue, $error)
Expand Down Expand Up @@ -231,7 +231,7 @@ Describe "Test-ModuleManifest Performance bug followup" -tags "CI" {
It "Test-ModuleManifest should not load unnessary modules" {

$job = start-job -name "job1" -ScriptBlock {test-modulemanifest "$using:UserModulesPath\ModuleWithDependencies2\2.0\ModuleWithDependencies2.psd1" -verbose} | Wait-Job

$verbose = $job.ChildJobs[0].Verbose.ReadAll()
# Before the fix, all modules under $pshome will be imported and will be far more than 15 verbose messages. However, we cannot fix the number in case verbose message may vary.
$verbose.Count | Should -BeLessThan 15
Expand Down