Can I refer from a UWP project to a .NET Standard project? - c#

I created an UWP app, and a .NET 6.0 project, and added reference of UWP project to the .NET 6 project.
Output of executing proj.bat file that runs this solution executes the following error:.
Error NU1201: Project MyUWPProject is not compatible with net6.0 (.NETCoreApp,Version=v6.0). Project MyUWPProject supports
: uap10.0.18362 (UAP,Version=v10.0.18362)
How can fix this? Is what I'm trying to do even possible?

The error message shows that the environment of your .NET 6.0 project is .net6.0 and the environment of the UWP project doesn't support .net6.0. So the UWP project is not compatible with the .NET project.
If you want to use Windows Runtime APIs, you could just make some confirugation in for your .NET 6.0 porject so that you could directly call Windows Runtime APIs in your app. You will need to Edit Your Project File and Modify TargetFramework Element to net6.0-windows10.0.19041.0.
You could check this document - Call Windows Runtime APIs in desktop apps for detailed steps.

Related

Build Pjsip windows sdk/.net 6 target dll

I am trying to create a pjsip dll and add it to an Uwp app. I have built a dll following this (working fine for WPF). Which gives an error while adding dll to the Uwp project saying unsupported-frameworks don't match as uwp targets Windows SDK. Creating a .net standard 2.0 class library as a bridge also didn't work.
At first, I found this solution. But this also produces more errors.
Now, I want to create a dll for Pjsip and use it in my UWP app. I am badly in need of a solution for creating windows SDK using pjsip or a suggestion regarding workarounds to use the current win32 .net framework targetted dll in the uwp project.
I have build pjsua2 dll and working fine using this link

Unable to add a reference to project - UWP to Class Library project?

A WPF project and a UWP project share the same solution. Can both projects reference a common project?
"Common" - .NET 6 target framework, class library
"UWP" - targets Windows 10 Creators Update (Build 15063)
"WPF App" - .NET 6 target framework, references "WPF2"
"WPF2" - .NET 6 target framework
The "WPF" project can reference "Common" no problem, but the "UWP" project says "Unable to add a reference to project 'Common'".
Annoyingly, the error message does not give a reason why.
How to use a class from one C# project with another C# project
Common controls for UWP and WPF
Reference a class library from UWP and ASP.NET 5 (solution here)
UWP is not compatible with .NET Core or .NET 6.
If you want to share code between a WPF app and a UWP app, your shared project should target .NET Standard 2.0.
Please refer to the docs for more information about .NET Standard and the supported .NET implementations for each version.

Add Package support framework to a .Netcore 3.1 app (WPF) through Visual Studio MSIX packaging

I have a .netcore 3.1 WPF app and I'm using a MSIX packaging project through visual studio for distribution. Is it possible to add PSF to a .netcore 3.1 app?. Basically what I'm trying to do is, I want the MSIX installer to add a desktop shortcut automatically after the installation is done.
This is the approach I'm following: https://learn.microsoft.com/en-us/windows/msix/psf/create-shortcut-with-script-package-support-framework
I also found this guide on how to add PSF to visual studio: https://learn.microsoft.com/en-us/windows/msix/psf/package-support-framework-vs. It uses a c++ project to run a .dll, but I think that's only compatible with .net framework and it's not compatible with .netcore. Can anyone please help me?
You don't need to use the package support framework.
The PSF is recommended for cases when IT pros don't have access to the source code of the application and basically, they need an additional launcher (the psflauncher.exe) to execute additional code or redirect API calls before they get to the application.
In your case, all you need is to add a few lines of code inside your startup/main method of your application to create the shortcut.
Remember, the trick is to run this code only the first time the application is launched and if the shortcut isn't already on the desktop.

How to package a WPF (.NET Core) app with XamlIslands and Desktop Bridge?

I have an application in WPF targeting .NET Core v3.1 and I'm using XamlIslands to display Windows 10 UI components. In order to use XamlIslands, I had to first migrate my app from .NET Framework to .NET Core.
I put my custom UWP components into a UWP project, which targets Win10 version 2004, min version is 1903. And in the WPF project I can reference these custom UWP components using XamlHosts.
Then, I have a Desktop Bridge project, which can package the WPF application, to be able to upload to the Microsoft Store.
The project compiles and runs correctly, I can run even the packaging project, but when I try to create a sideloaded App Package, it gives me the following error:
Project UWP is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1) / win-x64. Project UWP supports: uap10.0.18362 (UAP,Version=v10.0.18362)
Project UWP is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project UWP supports: uap10.0.18362 (UAP,Version=v10.0.18362)
I tried to set the min version for the UWP app to windows 10, build 10240 (this is the oldest one), but the same error appeared (of course, with the updated uap version).
In this answer I read that maybe I should create a .NET Standard project? But there is no way to create a WPF application targeting .NET Standard.
How the error message says that the UWP app is not compatible with .netcore when I could build and run the whole solution? If it runs, why can't create an App Package?
How can I create an App Package then, which I can upload to the Store?
How to package a WPF (.NET Core) app with XamlIslands and bridge?
Please refer Host a custom WinRT XAML control in a WPF app using XAML Islands official document. And derive from your information, it looks you have not configured your solution to target a specific platform such as x86 or x64. Custom WinRT XAML controls are not supported in projects that target Any CPU.
And please don't forget edit your wpf project configuration
<AssetTargetFallback>uap10.0.19041</AssetTargetFallback>
I have make a code sample and I could make the package base on above steps, here is official code sample, you could download it and test to make a package.

Dotnet 4.0 upgrade from 2.0

i am working on a dotnet C# web application which was initially created with VS 2003. My goal is to upgrade this application to Dotnet 4.0 without changing any functionaltiy. The solution has 9 projects (1 web + 8 Library projects). The Web project refers the 8 libraries in DLLs. To start off, I created a New project in VS2010 and added the all the Project files from the existing source code. Every time i add a project file to my solution, i was prompted with the Converison wizard and i completed the conversion wizard succesfully and now the solution works fine. After the conversion, i noticed that Except the "Web" project, other projects are converted to Dotnet 2.0 but not 4.0. My application runs without error if i run it locally using VS2010. My questions are
Why the Class libaray project did not upgrade to 4.0? Currently the
Web project is shows up as Dotnet 4.0 and Libaray projects shows up
as Dotnet 2.0.
Can i deploy the application to IIS 7.0 with the
Dotnet runtime of 4.0? Will the Dlls created in version 2.0 work if my application
uses Dotnet 4.0 runtime version?
Please help...
If your'e migrating now, why not move directly to Visual Studio 2012, instead of 2010?
Anyway, what you can do is open the project properties in each of your projects, and change the target framework to the .NET framework 4.0.
Then if you get any compilation error you can probably easily solve it individually. This should be relatively easy if your projects are not too big.
As for your specific questions:
The automatic conversion would only change the format of the solution/projects to be compatible with the new version Visual Studio. It shouldn't change the target framework but you can change that yourself.
Yes, assemblies targeting .NET 2.0 can be loaded and used from assemblies targeting .NET 4.0.
1) Upgrading the solution/projects file only upgrades it's format so you can open it in VS 2010. It will usually leave the targeted .NET setting at the previous value. These are two seperate things. The wonderful thing about VS 2010 is it let's you target whatever version of .NET you desire, so no longer do you need multiple version of VS installed to support differnt .NET versions. It didn't change the targetted .NET version because it leaves it up to you. You can change it under the project settings and recompile your library projects to regenerate the DLLs
2) You will need an application pool for .NET 4. .NET is backwards compatible in that a .NET 2.0 app can run on a machine with .net 4 installed. However, the application pool for 2.0 applications must be separate from 4.0 apps. So it's just a matter of putting the app under the right app pool.

Categories

Resources