Microsoft.Graphics.Canvas.winmd cannot be referenced
TheAjaykrishnanR opened this issue · 5 comments
I had just installed Win2D from NuGet onto my WinUI 3 project, and it no longer compiles giving the following error :
Severity Code Description Project File Line Suppression State
Error NETSDK1130 Microsoft.Graphics.Canvas.winmd cannot be referenced. Referencing a Windows Metadata component directly when targeting .NET 5 or higher is not supported. For more information, see https://aka.ms/netsdk1130 WinNotes C:\Program Files\dotnet\sdk\7.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets 1033
This is the project solution :
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>WinNotes</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
</PropertyGroup>
<ItemGroup>
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\Square150x150Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Assets\StoreLogo.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.1.1" />
<!--PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.4" /-->
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231115000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
<!--
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
Tools extension to be activated for this project even if the Windows App SDK Nuget
package has not yet been restored.
-->
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
<!--
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
Explorer "Package and Publish" context menu entry to be enabled for this project even if
the Windows App SDK Nuget package has not yet been restored.
-->
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>
</Project>
When I use the CsWinRT package as microsoft's official solution to 1130 says, it compiles but the programs exists with 0x80008089. I surely am missing something.
Try updating your TargetFramework to 22621, that should do the trick. I think you won't need to use the CsWinRT package.
You can leave the TargetPlatformMinVersion as is, that should still work fine.
Edit: Just for clarity, it should look like this:
<TargetFramework>net6.0-windows10.0.22621.0</TargetFramework>
thanks, but now I get :
Severity Code Description Project File Line Suppression State
Error NETSDK1148 A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. Please update to a newer .NET SDK in order to reference this assembly. WinNotes C:\Program Files\dotnet\sdk\7.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Windows.targets 55
I installed .NET SDK 8.0 and placed a global.json inside my solution specifying it but to no avail
That's strange, the rest of your project file looks good to me, and Win2D was compiled using .NET 6.0.
Two questions:
- Are you building in VS? If so, I've seen an occasional bug where VS needs to be restarted to correctly pick up the new SDK / .NET version.
- Is this a packaged project or unpackaged project?
That's strange, the rest of your project file looks good to me, and Win2D was compiled using .NET 6.0.
Two questions:
1. Are you building in VS? If so, I've seen an occasional bug where VS needs to be restarted to correctly pick up the new SDK / .NET version. 2. Is this a packaged project or unpackaged project?
- Yes I am using VS 2022, i will try upgrading it
- its a packaged project
So I upgraded VS to 17.8.2 and now its compiling with Win2D included.