简体   繁体   中英

C# WPF - How to make a .dll of a namespace to use in other programs?

I have just created a namespace, with a set of windows, that tell the user about updates, that I would like to use in many of my applications.

I would like to just package the namespace as a .dll, and just use these windows wherever I please, without having to manually add any .xaml or .cs files, just the .dll.

How can I accomplish this?

If I understand you correctly, you will want to build the usable logic in a separate project, and then build type would be library. This will then build all the resources of that project as a dll. Alternative solutions could be package it as a nuget package to be installed through package manager.

Right click on your project (solution explorer), and select properties. In your application tab, output type should be Class Library. Just in case check your build tab to check your output path. If you built your project and it was all good, then your project .dll file should be inside bin/debug or bin/release, which you can then reference in any other projects you want.

If I am right then I think you are looking for importing all the namespaces of a DLL in a single XML namespace so that you can use the in your WPF or UWPxaml forms that particular technique is called Extending the WPF XML namespaces .

The way to do that is to open op a .cs file, I'd make one just for assembly configurations and add something like this:

[assembly: XmlnsDefinition("http://www.asp-waf.com/Desktop/2021/xaml","Desktop.Model")]
[assembly: XmlnsDefinition("http://www.asp-waf.com/Desktop/2021/xaml","Desktop.Model.Desktop")]
[assembly: XmlnsDefinition("http://www.asp-waf.com/Desktop/2021/xaml","Desktop.Model.UserAgent")]
[assembly: XmlnsDefinition("http://www.asp-waf.com/Desktop/2021/xaml","Desktop.Infrastructure")]
[assembly: XmlnsDefinition("http://www.asp-waf.com/Desktop/2021/xaml","Desktop.Model.Infrastructure")]
[assembly: XmlnsDefinition("http://www.asp-waf.com/Desktop/2021/xaml","Walter.Net.Networking",AssemblyName="Walter.Net.Networking")]
[assembly: XmlnsDefinition("http://www.asp-waf.com/Desktop/2021/xaml","Walter.BOM",AssemblyName="Walter.BOM")] 

in the definition I import all namespaces for the current dll "Desktop.Model.dll" and map them to the HTTP uri, you can pick any uri that you like.

I also link some external namespaces I use from 2 dll's that I have loaded as NuGet packages in my project and added them to.

You can also merge the default namespaces you keep adding and have them all as a 1 liner, here is a good explanation of how it can be used https://paulstovell.com/xmlnsdefinition/

Compile the project and IntelliSense will pick up the URI when upade your xaml files and life becomes "less frustrating"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM