unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.93k stars 725 forks source link

`The SDK 'Uno.Sdk' specified could not be found.` when adding a Library project without global.json #18619

Open AndrewKeepCoding opened 1 week ago

AndrewKeepCoding commented 1 week ago

Current behavior

I get the following error dialog when creating/adding a new Uno Platform Library project.

image

These files are created but not loaded to the solution.

image

The created global.json and .csproj look good to me.

global.json

{
  "msbuild-sdks": {
    "Uno.Sdk": "5.4.10"
  }
}

.csproj

<Project Sdk="Uno.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net8.0;net8.0-ios;net8.0-maccatalyst;net8.0-android;net8.0-windows10.0.19041;net8.0-browserwasm;net8.0-desktop</TargetFrameworks>
    <UnoSingleProject>true</UnoSingleProject>
    <OutputType>Library</OutputType>
    <!-- Ensures the .xr.xml files are generated in a proper layout folder -->
    <GenerateLibraryLayout>true</GenerateLibraryLayout>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <!--
      UnoFeatures let's you quickly add and manage implicit package references based on the features you want to use.
      https://aka.platform.uno/singleproject-features
    -->
    <!--
    <UnoFeatures></UnoFeatures>
    -->
  </PropertyGroup>

  <ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
    <!--
    If you encounter this error message:

      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.

    This means that the two packages below must be aligned with the "build" version number of
    the "Microsoft.Windows.SDK.BuildTools" package above, and the "revision" version number
    must be the highest found in https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref.
    -->
    <!-- <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" RuntimeFrameworkVersion="10.0.22621.28" />
    <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.22621.28" /> -->
  </ItemGroup>
</Project>

Expected behavior

Creates/Adds an Uno Platform Library without errors.

Affected platforms

No response

Template Host

Visual Studio

Host OS

Windows

Template Options

Just [Add a new project] -> [Uno Platform Library] on Visual Studio 2022 [Preview].

Template Version

Uno Platform Extension v5.4.14.16

Anything else we need to know?

jeromelaban commented 1 week ago

Thanks for the report.

This is likely a misconfiguration of Visual Studio of some kind. Can you validate that the app that has been created (it should be on the disk even if VS does not load it) can be compiled using dotnet new on the command line?

AndrewKeepCoding commented 1 week ago

Hi @jeromelaban ! Do you mean dotnet build? The first time got an error mentioning WindowsSdkPackageVersion. After adding:

<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>

on the Uno Library *.csproj, the build successed.

jeromelaban commented 1 week ago

Do you mean dotnet build?

I did, my apologies :)

It's interesting that you're getting that particular error. Is it loading in VS after this?

AndrewKeepCoding commented 1 week ago

Is it loading in VS after this?

No. Same error. I'm not the only one by the way. @ArchieCoder gets the same behavior. 🤔

jeromelaban commented 1 week ago

Would you have private nuget feed that is not working in your nuget feeds list?

AndrewKeepCoding commented 1 week ago

Just in case, here is my Visual Studio version:

Microsoft Visual Studio Enterprise 2022 (64-bit) - Preview Version 17.12.0 Preview 4.0

ArchieCoder commented 1 week ago

I tried in Andrew's solution and yeah I got the bug.

I tried in my solution and it works.

I'm on regular VS version.

jeromelaban commented 1 week ago

@AndrewKeepCoding are you able to provide a repro?

AndrewKeepCoding commented 1 week ago

This is the repo. I get the error trying to add an Uno Platform Library.

https://github.com/AndrewKeepCoding/WinUI3Localizer/tree/uno-platform

AndrewKeepCoding commented 1 week ago

In my environment, I get the same behavior trying to create/add a brand-new Uno Platform Library...🤔

jeromelaban commented 1 week ago

Thanks. Indeed I can reproduce the problem. The issue here is caused by the fact that VS does not provide a good way for determining that global.json should be used or not, and where.

The workaround, so far, is to go to the folder that was created, move the global.json file next to the sln, then add the csproj manually.

AndrewKeepCoding commented 1 week ago

@jeromelaban Thank you for the quick support! I confirmed that the workaround works!