1

I am developing a Windows Studio CLI Project to deploy on other machines and was wondering two things if this is the right project type to deploy a solution that uses the Windows.Management.Deployment library because the namespace is not being recognized by the solution file. I have already done some research on Stack Overflow and implemented the following in my .csproj file.

<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>

Thus far what I have tried have seemed to not be working and I am doubting if my setup is complete. If there are suggestions on how I could get this library to work this is the beginning declarations in my C# file.

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

The line that is causing issues is this line:

var packageManager = new PackageManager();

I am also linking a question which I found useful but did not work in my setup in case somebody comes across this question. How to access Windows.Management.Deployment namespace in a Desktop project in VS2017?

I am using the Nuget Package Manager when I tried to use WindowsRuntime 4.7.0 it said it was unavailable to user.

Edit to `.csproj`

<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>
Narish
  • 607
  • 4
  • 18
Wanderer
  • 13
  • 5
  • When you say you looked at that other question, does that include the link in the comment saying how things have changed since .NET 5? (I'm guessing not given your `TargetFramework` values compared to what it [should be](https://learn.microsoft.com/en-gb/dotnet/core/tools/sdk-errors/netsdk1130)) – Damien_The_Unbeliever Jan 10 '23 at 15:26
  • @Damien_The_Unbeliever I edited my .csproj file does that reference the Nuget reference package? Because I just added that using Nuget and the reference appeared. – Wanderer Jan 10 '23 at 15:34

1 Answers1

0

What ended up solving the issue was the fact that the metadata was not referenced properly so I had to change the target framework.

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

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

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

   
</Project>

This solved the problem for me at least.

Wanderer
  • 13
  • 5