简体   繁体   中英

Visual Studio 2019 - Could not locate the assembly “Windows”

I'm trying to use this PoshWinRT .NET/Powershell library , as described in this blog post , and this SO question . This worked for me before on Windows 7, but now I am on Windows 10 and since I've moved to a new computer I've cleared the assemblies cached during the build.

The code uses several classes such as Windows.Foundation.IAsyncAction, which are failing because of a missing "Windows" assembly:

CS0012 The type 'IAsyncAction' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'. PoshWinRT D:\projects\PoshWinRT\PoshWinRT\AsyncActionWrapper.cs 21

As well as an error about that assembly:

Could not resolve this reference. Could not locate the assembly "Windows". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

In the right-hand Solution Explorer, the following properties are shown for the "Windows" dependency in my References list:

在此处输入图像描述

The above .winmd has been deleted, but now I'm not sure how to re-add it. I've tried adding things like:

System.Windows
Windows.Foundation
Windows.Storage
Windows.System

But without any luck. How do I re-add the "Windows" assembly? I am guessing that either classes have moved around since I last used this code or maybe this is a wrapper for native code that needs to be included in some special way. Or maybe I don't have the right library installed. I've installed the VS WinRT extension, but that didn't help.

I should say that I'm hoping to import this in pwsh (core), where before it was running in pre-core powershell.

The windows.winmd is part of the Windows 10 SDK .

在此处输入图像描述

You can find the file for the Buildnumber of your installed SDK under C:\Program Files (x86)\Windows Kits\10\

For anyone that's encountering the followings errors:

The type 'IAsyncAction' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

The type 'IAsyncActionWithProgress<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

The type 'IAsyncOperation<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

The type 'IAsyncOperationWithProgress<,>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

and is using reactive extensions package , the errors might be due to a conflict with the package System.Runtime.WindowsRuntime .

Just remove that package and the errors will disappear.

More info here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM