Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't add a new Uno application project to an existing solution in VS2022 #16973

Open
LegacyNsfw opened this issue Jun 1, 2024 · 13 comments
Open
Labels
blocked/vs Categorizes an issue as blocked by a Visual Studio problem kind/tracking-only Categorizes an issue that is currently open for tracking purposes only.

Comments

@LegacyNsfw
Copy link

Current behavior

Repro steps:

  1. I have an existing Visual Studio solution that contains a couple of WinForms applications and a couple of .Net Standard libraries.
  2. I would like to add an Uno application (which will eventually replace the WinForms applications).
  3. I used uno-check to add the Uno dependences.
  4. I downloaded and installed the Uno extension (vsix file).
  5. I loaded the solution, right-clicked on the top root node of the solution, and picked Add, Add New Project...
  6. I picked "Uno Platform App" from the list of project templates
  7. I added a project name
  8. I clicked "Create"

Expected results: an Uno application project is added to my solution.

Actual results: This dialog:

image

Note that there is no "same directory" checkbox on the previous screen.
That option only exists when creating a new solution.
I am not creating a new solution. I am adding a new project to an existing solution.

Expected behavior

After clicking "Create" there should be a new Uno Application project in my existing solution, alongside the existing projects.

How to reproduce it (as minimally and precisely as possible)

Unzip this file, open the solution inside it, try to add a new Uno Platform application as described above.
UnoNewAppRepro.zip

Workaround

I don't know of one.

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

No response

Affected platforms

Windows (WinAppSDK)

IDE

Visual Studio 2022

IDE version

17.9.6

Relevant plugins

No response

Anything else we need to know?

If someone can point me to where the code is, I'm willing to take a shot at fixing this. But first I'd like to know why (or whether) this requirement seemed like a good idea in the first place. Even for new solutions, unless the application is tiny, it's normal to have multiple projects in subdirectories beneath the directory that contains the solution file.

Is there any scenario in which this "same directory" requirement is truly required, by-design?

Is other work required, in order to properly support the not-same-directory scenario?

@LegacyNsfw LegacyNsfw added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Jun 1, 2024
@jeromelaban
Copy link
Member

Thanks for the report. We're currently hitting a limitation of Visual Studio, where VS does not allow for custom sln files provided by a nuget package. The code for this part is not public a this time.

The best way, for now, to add a new project in an existing solution is either by creating it from a separate visual studio instance, then copy the project to the appropriate location, or by using dotnet new (using https://new.platform.uno).

@LegacyNsfw
Copy link
Author

Thanks!

@MartinZikmund MartinZikmund added blocked/vs Categorizes an issue as blocked by a Visual Studio problem kind/tracking-only Categorizes an issue that is currently open for tracking purposes only. and removed kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Jun 4, 2024
@ab-tools
Copy link

Just ran into the same issue here - a pity that this cannot be fixed as it might block new users getting into the Uno Platform if they hit this issue at the very start...

@jeromelaban
Copy link
Member

@ab-tools We understand the issue, and we have no fix this at this time, as I mentioned above.

@LegacyNsfw
Copy link
Author

I'm having trouble with the suggested workaround...

  1. Create a new Uno application project (Windows + Android + iOS + Linux, with XAML)
  2. Build the app successfully
  3. Copied the directory into an existing solution
  4. Tell Visual Studio to build the project in that existing solution
  5. Build fails due to fill file paths in obj/project.assets.json
  6. Delete the obj directory
  7. Tell VS to build the project again...

Expected result: it builds

Actual result: "1>C:\GitHub\PcmHammer\Apps\PcmHammer2\App.xaml.cs(70,32,70,57): error CS0103: The name 'ReactiveViewModelMappings' does not exist in the current context"

I saw this discussion about needing to install the Uno.Extensions.Reactive package:

#10214

The package manager UI indicates that it's already installed as a transitive dependency. I hit the install button anyway, but still get the same compiler error.

What steps should I take to troubleshoot this problem?

@jeromelaban
Copy link
Member

I'm having trouble with the suggested workaround...

It is likely that you have nuget restore issues. Uno apps depend on global.json, as well as the Directory.Build.props/.targets. Make sure to include the contents of those files in your existing solution.

@LegacyNsfw
Copy link
Author

LegacyNsfw commented Dec 7, 2024

I moved global.json and the Directory.Build files into the same directory as the .sln file, and that got me a different error message. I have a .Net Standard 2.0 library in this solution, which apparently isn't compatible with the Uno configuration:

error NU1008: Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: Microsoft.Bcl.HashCode;DynamicExpresso.Core;System.Xml.XmlSerializer;System.Collections.Immutable;Newtonsoft.Json.
2>Done building project "PcmLibrary.csproj" -- FAILED.

I realize this is a Microsoft problem rather than an Uno problem, but that error message would have been a lot more helpful if it had indicated that PackageReference is an element in the .csproj file, and PackageVersion is an element in the Directory.Build.props file.

Just thought I'd document this stuff for anyone else who ends up in the same predicament.

@LegacyNsfw
Copy link
Author

LegacyNsfw commented Dec 7, 2024

Fixing that problem got me to a new error message about using Nullable with less-than-latest version of C#, and again Microsoft offers few clues about where these configuration settings are located.

The fix was to add 12.0 to Directory.Build.props under Project/PropertyGroup.

Now I have a bunch of warnings about null variables that were not declared nullable, but that's probably a good thing in the long run.

And this is also not really an Uno problem, but something that maintainers of existing projects might run into on the road to Uno. Especially if those projects have been around for a few years.

@LegacyNsfw
Copy link
Author

That said... I still have the missing ReactiveViewModelMappings problem:

1>C:\GitHub\PcmHammer\Apps\Uno\PcmHammer2\App.xaml.cs(70,32,70,57): error CS0103: The name 'ReactiveViewModelMappings' does not exist in the current context

Which package is needed to resolve that issue?

Or maybe I should ask, what is it that invokes BindableViewModelMappingGenerator during the build?

I copied the global.json, Directory.Build.props, Directory.Build.targets, and Directory.Packages.props files that were created with my Uno project into the .sln directory of my existing project. and running "restore nuget packages" just prints "All packages are already installed and there is nothing to restore.

Global.json:

  // To update the version of Uno please update the version of the Uno.Sdk here. See https://aka.platform.uno/upgrade-uno-packages for more information.
  "msbuild-sdks": {
    "Uno.Sdk": "5.4.8"
  },
  "sdk":{
    "allowPrerelease": false
  }
}

Directory.Packages.props has a few added packages needed by my existing code:

<Project ToolsVersion="15.0">
  <!--
    To update the version of Uno, you should instead update the Sdk version in the global.json file.

    See https://aka.platform.uno/using-uno-sdk for more information.
    See https://aka.platform.uno/using-uno-sdk#implicit-packages for more information regarding the Implicit Packages.
  -->
  <ItemGroup>
    <PackageVersion Include="coverlet.collector" Version="6.0.2" />
    <PackageVersion Include="FluentAssertions" Version="6.12.0" />
    <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
    <PackageVersion Include="NUnit" Version="4.1.0" />
    <PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
    <PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
    <PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageVersion Include="Uno.UITest.Helpers" Version="1.1.0-dev.70" />
    <PackageVersion Include="Xamarin.UITest" Version="4.3.4" />
    
    <PackageVersion Include="DynamicExpresso.Core" Version="2.3.1" />
    <PackageVersion Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
    <PackageVersion Include="System.Collections.Immutable" Version="7.0.0" />
    <PackageVersion Include="System.Xml.XmlSerializer" Version="4.3.0" />
  </ItemGroup>
</Project>

Directory.Build.props:

<Project>
  <PropertyGroup>
    <LangVersion>12.0</LangVersion>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>

    <!--
      Adding NoWarn to remove build warnings
      NU1507: Warning when there are multiple package sources when using CPM with no source mapping
      NETSDK1201: Warning that specifying RID won't create self containing app
      PRI257: Ignore default language (en) not being one of the included resources (eg en-us, en-uk)
    -->
    <NoWarn>$(NoWarn);NU1507;NETSDK1201;PRI257</NoWarn>
  </PropertyGroup>
</Project>

@jeromelaban
Copy link
Member

Thanks for the updates.

The BindableViewModelMappingGenerator is automatically included when the Reactive uno feature is present. If it's not present, it would mean that either the csproj is incorrectly configured, or that the uno.sdk is not setup properly.

It would help if you were to replicate your solution in repro sample so we could guide you.

@LegacyNsfw
Copy link
Author

What determines whether the Reactive feature "is present?"
Are we talking about a config file, or a checkbox in the UI, or something else?

Note that this same csproj and source files build and run just fine in the directory where the project was created, so everything needed is present on my machine.

The code I'm working with is in the nsfw/net8-uno-ui branch of this repo:
https://github.com/PcmHammer/PcmHammer.git

You can browse it here:
https://github.com/PcmHammer/PcmHammer/tree/nsfw/net8-uno-ui

PcmHammer2 is the Uno project.

There's a ton of other stuff in that repo since it's an existing project and I'm trying to give it an Uno UI. If you'd prefer, I can try creating a smaller simpler .sln, and the add the Uno project to that.

Thanks!

@jeromelaban
Copy link
Member

The feature Reactive is set using the UnoFeatures property. Is it set in your project?

@LegacyNsfw
Copy link
Author

These are the features - Reactive is not in the list:

   <UnoFeatures>
      Material;
      Dsp;
      Hosting;
      Toolkit;
      Logging;
      MVUX;
      Configuration;
      Localization;
      Navigation;
      ThemeService;
    </UnoFeatures>

Adding Reactive to the list led to this error when I try to build in VS:

1>C:\Users\nate.nuget\packages\uno.sdk\5.4.8\targets\Uno.Implicit.Packages.targets(33,3): warning : Unable to parse 'reactive' to a known Uno Feature.

Also, Reactive is also not in the csproj file in the standalone Uno project, which builds and runs. The files are identical since I just copied the generated file into the existing solution, along with everything else.

Should I be using a version other than 5.4.8?

I don't recall choosing a version when I installed Uno or when I created the project, so I assume it was just the latest available when I installed the Uno extension.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/vs Categorizes an issue as blocked by a Visual Studio problem kind/tracking-only Categorizes an issue that is currently open for tracking purposes only.
Projects
None yet
Development

No branches or pull requests

4 participants