Is it possible to use WPF within an .NET Standard Class Library or is this to be reserved for .NET Core? If so, is it possible to setup a .NET Core Class Library that uses WPF or does it necessarily have to be a .NET Core App?
Finally, I got in contact with Microsoft. They were very helpful and provided the following snippet of a *.csproj file to me:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
With this, I get a .NET Core class library including WPF. Additionally, I had to remove App.xaml and App.cs. This was necessary since those contain <Application> tags in XAML which aren’t allowed in WPF libraries.
Related
This question already has answers here:
How to access the Dispatcher from a .net Core 3.1 dll (WPF)
(2 answers)
Closed 2 years ago.
I'm a long time WPF (.Net Framework) developer finally dipping my toes into .Net Core for the first time. I'm currently trying to convert a small v4.7.2 WPF application to .Net Core 3.1. The solution contains a WPF app project and a class library project, with only a handful of classes each, so I decided it would be easier to create a new solution containing a WPF app and class library project (both .Net Core 3.1), then copy the cs and xaml files from the original solution. However I seem to be falling at the first hurdle...
Many of the classes use types from the System.Windows namespace (and System.Windows.Media, System.Windows.Controls, etc). These resolve fine in the WPF app project but not the class library. I've noticed the WPF app project has a reference to the framework "Microsoft.WindowsDesktop.App.Wpf", but the class library project doesn't, which I assume is my problem. However I can't for the life of me figure out how to add this framework into the project. How do I do it?!
I've seen solutions elsewhere of adding <UseWPF>true</UseWPF> to the class lib csproj file, but this has no effect.
As usual, no sooner do I post the question than I find the answer. I also had to change the SDK in the csproj file to:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
We have an application where the main UI is coded in vb6. We also have multiple .net assemblies (winform and class libraries) built in vb.net (VS2015, targeting framework 4.5.2).
Can we utilize the winform dotnetbrowser in a .net assembly that is called via com interop from our vb6 main app?
The licensing articles instruct adding the license to the project as an embedded resourse - would this license be added to the .net assembly as an embedded resource? Or would it need to be added to the main app exe (vb6) as an embedded resource there?
Can we utilize the winform dotnetbrowser in a .net assembly that is called via com interop from our vb6 main app?
Yes, this use-case is possible.
The licensing articles instruct adding the license to the project as an embedded resourse - would this license be added to the .net assembly as an embedded resource? Or would it need to be added to the main app exe (vb6) as an embedded resource there?
There are several ways to provide the licence to DotNetBrowser:
the most common and recommended way is to include the licence into
the application .NET assembly as an Embedded Resource (it is
usually done when performing a build)
the other common way is putting
the licence file into the working directory of the application that
loads and uses DotNetBrowser
at last, you can specify the full path to the
licence file using the DOTNETBROWSER_LICENSE_PATH environment
variable
I'm porting a WPF app over to Windows Store app. I have some view models that I would like to put into a Portable Class Library. That code uses reactiveui framework. I created the library and I use nuget package manager to add reactiveui to the project. I get this:
Could not install package 'reactiveui-platforms 5.4.0'. You are trying to install this package into a project that targets 'portable-net45+wp80+win', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Is this really an unsupported configuration or am I doing it wrong?
ReactiveUI-Platforms is specifically only the platform-specific code. You need to just reference ReactiveUI-Core in your PCL and reference ReactiveUI-Platforms in your WPF and Windows Store apps, and everything should work.
I have created a VS2013 solution that contains multiple projects. One of those projects is a portable class library targeting .NET 4.5+, Silverlight 5, Windows Store 8+ and Windows Phone 8 and this project contains a reference to an OData service in an accompanying web application.
The portable class library references Microsoft.Data.Services.Client.Portable (among others), added via nuget (WCF Data Services Client).
I have then added the portable class library to a WPF (.NET 4.5) application, a Windows Store application and a Windows Phone application and written some very basic test code to access the service. This works fine in Windows Store and Windows Phone.
The WPF application however will not compile. The errors are...
The type 'System.Data.Services.Client.DataServiceContext' is defined
in an assembly that is not referenced. You must add a reference to
assembly 'Microsoft.Data.Services.Client.Portable, Version=5.6.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
The type 'System.Data.Services.Client.DataServiceQuery`1' is defined in an
assembly that is not referenced. You must add a reference to assembly
'Microsoft.Data.Services.Client.Portable, Version=5.6.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
The thing is, I also added the WCF Data Services Client to the WPF application via nuget, but it does not add a reference to the portable library (packages\Microsoft.Data.Services.Client.5.6.0\lib\portable-net45+sl5+wp8+win8\Microsoft.Data.Services.Client.Portable.dll), instead adding a reference to the full framework 4.0 version (packages\Microsoft.Data.Services.Client.5.6.0\lib\net40\Microsoft.Data.Services.Client.dll) - which in turn is causing the error I am seeing.
Is there something I am doing wrong here or is this an error in the installation package? Note that if I delete the offending reference and add the alternative reference manually then all is well so though I have a work-around I would still like to know if I am the cause of the error.
Looking at the NuGet source code this behaviour seems to be by design.
The WCF Data Services Client contains assemblies for the following frameworks:
.NET Framework, v4.0
.NET Portable, net45, sl5, wp8, win8
Silverlight, v4.0
Installing this NuGet package into a project that targets .NET 4.5 will result in the .NET 4.0 assembly from the NuGet package being referenced. NuGet considers the more specific .NET framework to be a better match for your WPF project which targets .NET 4.5.
There is a comment in the NuGet source code about this when it looks for the best matching assembly in the NuGet package.
// Let's say a package has two framework folders: 'net40' and 'portable-net45+wp8'.
// The package is installed into a net45 project. We want to pick the 'net40' folder, even though
// the 'net45' in portable folder has a matching version with the project's framework.
I've got a Problem. I need to use some classes from another Library DLL, that has been written a year ago, in my WPF Project. Therefore I reference this Library in my Project. But when I want to rebuild my solution I always get some warnings that my assembly cannot be resolved because it uses some dependencys that do not match my targeted framework.
This is one of the Errors
The referenced assembly "istis.AcademyOne.ClassLibrary, Version=2.1.0.1, Culture=neutral, PublicKeyToken=fd9f6afaca722199, processorArchitecture=MSIL" could not be resolved because it has a dependency on "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project. A1RevisionControls
Does anyone know a workaround or a solution so I can keep the original DLL and use it in my WPF Application ?
EDIT : Ok I solved the Problem switching my Target Framework of my WPF Solution to .NET Framework 4.0 instead of Framework 4.0 Client Profile.
One method would be to put the old dll behind a WCF facade. Another option would be to include the old dll in a new project, and use some sort of inter-process communication like named pipes to talk between the two.
Or you could just share the class files with a new .Net 4 class project, and reference that new class library. This example and this example talk about doing it in Silverlight and/or WCF, but the principle is exactly the same.