You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio专业版Windows CLI项目中使用Windows.Management.Deployment库的问题求助

Visual Studio专业版Windows CLI项目中使用Windows.Management.Deployment库的问题求助

大家好,我正在开发一个Windows Studio CLI项目,打算部署到其他机器上,现在遇到两个问题想请教各位:

  1. 这个项目类型是否适合用来开发依赖Windows.Management.Deployment库的解决方案?
  2. 目前我的解决方案无法识别这个命名空间,我已经做了一些研究和尝试,但都没解决问题,想问问有没有可行的修复建议。

我目前的尝试情况:

一开始我在Stack Overflow上查了相关内容,给.csproj文件做了如下配置:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Reference Include="System.Runtime.WindowsRuntime">
<HintPath>..\..\..\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>
</ItemGroup>

</Project>

在我的C#文件里,开头的引用是这样的:

using System;
using Windows.Management.Deployment;
using System.Linq;

报错的代码行是:

var packageManager = new PackageManager();

之后我又修改了.csproj,尝试添加NuGet包:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Runtime.InteropServices.WindowsRuntime" Version="4.3.0" />
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Runtime.WindowsRuntime">
<HintPath>..\..\..\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>
</ItemGroup>

</Project>

但尝试安装WindowsRuntime 4.7.0时,NuGet提示该包对我不可用。另外我还看过一个关于VS2017桌面项目访问Windows.Management.Deployment命名空间的问题,按照里面的方法操作也没解决我的问题。

现在我有点怀疑是不是自己的项目配置还不完整,恳请各位大佬给点建议,怎么才能让这个库正常工作?

备注:内容来源于stack exchange,提问作者Wanderer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 13:14:05