【发布时间】:2021-04-10 18:53:22
【问题描述】:
运行 Desired State Configuration 命令时:
Start-DSCConfiguration -ComputerName localhost -Path ./CsharpExample -Verbose -Wait -Force
我们得到以下错误:
InvalidOperation: Importing module cSharpDSCResource failed with error - Could not load file or assembly 'System.Management.Automation, Version=7.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
dll的目录结构:
"C:\Program Files\WindowsPowerShell\Modules\cSharpDSCResource\DSCResources\cSharpDSCResource\cSharpDSCResource.dll"
[appdomain]::CurrentDomain.GetAssemblies() | Sort-Object -Property FullName | Select-Object -Property FullName; returns from $PSVersionTable.PSVersion 5 prompt:
System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
[appdomain]::CurrentDomain.GetAssemblies() | Sort-Object -Property FullName | Select-Object -Property FullName; returns from $PSVersionTable.PSVersion 7 prompt:
System.Management.Automation, Version=7.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
我们无法弄清楚为什么它无法找到或加载 System.Management.Automation 7.1.0.0
Get-DSCResource 返回:
二进制 cSharpDSCResource cSharpDSCResource 0.0.1 {Path, Content, DependsOn, Ensure...}
我们正在使用windows管理框架:
微软网络 SDK 5.0.101
Visual Studio 代码中的项目代码:
cSharpDSCresource.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Management.Automation" Version="7.1.0" />
</ItemGroup>
【问题讨论】:
-
目标机器是否安装了 PowerShell Core 7.1?如果不是,则不能在其上使用任何 PowerShell 7.1 DSC。如果您有 PS 7.1,您是否使用 PowerShell Core 提示符运行
Start-DSCConfiguration? -
是的,我安装了 Powershell 7.1,在查找之后,PowerShell Core 7.1 是对 Powershell 6.0 的升级(均使用 .Net Core)。我使用 Powershell 7.1 提示符运行 Start-DSCConfiguration 并返回相同的错误。
-
你使用什么操作系统?
-
Windows Server 2019 标准版,版本 1809
-
尝试 netcoreapp3.1 作为 TargetFramework,结果相同。
标签: c# .net powershell resources dsc