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
26 changes: 0 additions & 26 deletions src/System.Management.Automation/engine/CommandDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,32 +486,6 @@ internal static void VerifyElevatedPrivileges(ExternalScriptInfo scriptInfo)
}
}

#region comment out RequiresNetFrameworkVersion feature 8/10/2010
/*
* The "#requires -NetFrameworkVersion" feature is CUT OFF.
* This method will be reenabled will be CUT OFF too
/*
internal static void VerifyNetFrameworkVersion(ExternalScriptInfo scriptInfo)
{
Version requiresNetFrameworkVersion = scriptInfo.RequiresNetFrameworkVersion;

if (requiresNetFrameworkVersion != null)
{
if (!Utils.IsNetFrameworkVersionSupported(requiresNetFrameworkVersion))
{
ScriptRequiresException scriptRequiresException =
new ScriptRequiresException(
scriptInfo.Name,
scriptInfo.NetFrameworkVersionLineNumber,
requiresNetFrameworkVersion,
"ScriptRequiresUnmatchedNetFrameworkVersion");
throw scriptRequiresException;
}
}
}
*/
#endregion

/// <summary>
/// Used to determine compatibility between the versions in the requires statement and
/// the installed version. The version can be PSSnapin or msh.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ private bool IsPs1xmlFileHelper_IsPresentInEntries(RemoteDiscoveryHelper.CimModu
return true;
}

if (manifestEntries.Any(s => FixupFileName(string.Empty, s, ".ps1xml").EndsWith(cimModuleFile.FileName, StringComparison.OrdinalIgnoreCase)))
if (manifestEntries.Any(s => FixupFileName(string.Empty, s, ".ps1xml", isImportingModule: true).EndsWith(cimModuleFile.FileName, StringComparison.OrdinalIgnoreCase)))
{
return true;
}
Expand Down
195 changes: 80 additions & 115 deletions src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; // for fxcop.
using System.Diagnostics.CodeAnalysis;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Internal;
Expand Down
6 changes: 0 additions & 6 deletions src/System.Management.Automation/resources/Modules.resx
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@
<data name="ModuleManifestInsufficientModuleVersion" xml:space="preserve">
<value>The version '{0}' of module '{1}' does not meet the required minimum version '{2}'. Verify that the version number is supported, and then try loading the module again.</value>
</data>
<data name="ModuleManifestInsufficientCLRVersion" xml:space="preserve">
<value>The version of the Common Language Runtime (CLR) on this computer is '{0}'. The module '{1}' requires a minimum CLR version of '{2}' to run. Verify that you are running the minimum required version of CLR, and then try again.</value>
</data>
<data name="ModuleManifestInsufficientPowerShellVersion" xml:space="preserve">
<value>The version of PowerShell on this computer is '{0}'. The module '{1}' requires a minimum PowerShell version of '{2}' to run. Verify that you have the minimum required version of PowerShell installed, and then try again.</value>
</data>
Expand Down Expand Up @@ -342,9 +339,6 @@
<data name="InvalidProcessorArchitecture" xml:space="preserve">
<value>The current processor architecture is: {0}. The module '{1}' requires the following architecture: {2}.</value>
</data>
<data name="InvalidDotNetFrameworkVersion" xml:space="preserve">
<value>The module '{0}' requires the following version of the .NET Framework: {1}. The required version is not installed.</value>
</data>
<data name="InvalidPowerShellHostName" xml:space="preserve">
<value>The name of the current PowerShell host is: '{0}'. The module '{1}' requires the following PowerShell host: '{2}'.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,51 @@ Describe "Get-Module -ListAvailable" -Tags "CI" {
$modules.Name | Sort-Object | Should -BeExactly $ExpectedModule
}
}

Context "Module analysis shouldn't load assembly" {
BeforeAll {
$tempModulePath = Join-Path $TestDrive "TempModules"
$testModuleDir = Join-Path $tempModulePath "MyModuelTest"
$moduleManifest = Join-Path $testModuleDir "MyModuelTest.psd1"
$assemblyPath = Join-Path $testModuleDir "MyModuelTestCommandAssembly.dll"

$null = New-Item $testModuleDir -ItemType Directory -ErrorAction SilentlyContinue
if (-not (Test-Path $moduleManifest))
{
Set-Content $moduleManifest -Value @'
@{
RootModule = 'MyModuelTestCommandAssembly.dll'
ModuleVersion = '0.0.1'
GUID = '5776ed43-1607-4e64-be76-acacdf8e9c8c'
FunctionsToExport = @()
CmdletsToExport = @("Get-Test")
AliasesToExport = @()
}
'@
}

$code = @'
using System.Management.Automation;

[Cmdlet("Get", "Test")]
public class MyModuelTestCommand : PSCmdlet
{
protected override void ProcessRecord()
{
WriteObject("BLAH");
}
}
'@
if (-not (Test-Path $assemblyPath))
{
Add-Type -TypeDefinition $code -OutputAssembly $assemblyPath
}
}

It "'Get-Module -ListAvailable' should not load the module assembly" {
## $fullName should be null and thus the result should just be the module's name.
$result = pwsh -c "`$env:PSModulePath = '$tempModulePath'; `$module = Get-Module -ListAvailable; `$fullName = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location -eq $assemblyPath | Foreach-Object FullName; `$module.Name + `$fullName"
$result | Should -BeExactly "MyModuelTest"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ namespace ModuleCmdlets
$loadedAssemblyLocation = pwsh -noprofile -c "Import-Module $destPath -Force; [Microsoft.PowerShell.ScheduledJob.AddJobTriggerCommand].Assembly.Location"
$loadedAssemblyLocation | Should -BeLike "$TestDrive*\Microsoft.PowerShell.ScheduledJob.dll"
}
}
}

Describe "Import-Module should be case insensitive" -Tags 'CI' {
BeforeAll {
Expand Down