I'm using VS2022, .NET7.0.
I'm trying to implement a function that automatically connects the SerialPort using USB's vid and pid.
I found that it was easier to implement by refering to this article rather than this article.
But, I can't use the Windows
namespace in Winform
.
I tried the Nuget\Install-Package Windows
using PM, but it failed.
I add the <TargetPlatformVersion>8.0</TargetPlatformVersion>
in .csproj
of project and looked at the References Manager, but it hasn't changed.
Tried reinstalling Windows SDK 10, same thing.
How to solve this problem?
CodePudding user response:
For a .NET 7, you do not need the NugetPackage, you need to edit the properties of the Project, and set the Target OS to 10.0.17763.0 or above. You can also modify the project file like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows10.0.17763.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
CodePudding user response:
As per @radian's comment, I solved it like this:
Opened NuGet Package Management and installed Microsoft.Windows.SDK.Contracts
.
I can now add Windows
namespace normally.
EDIT
When I do the above method, there is a problem that it does not compile.
To fix this, you need to act on this post or the accepted answer.