gpt4 book ai didi

.net - 如何打包针对通用Windows平台的.NET库?

转载 作者:行者123 更新时间:2023-12-02 23:02:45 25 4
gpt4 key购买 nike

如何以现代通用方式打包通用Windows平台库以通过NuGet发布?假设我有一个用C#编写的AnyCPU程序集,该程序集导出一些代码和XAML用户控件。


这是一系列问答,记录了我对现代NuGet软件包编写主题的发现,尤其着重于NuGet 3引入的更改。您可能还对一些相关问题感兴趣:


How to package a .NET Framework library?
How to package a portable .NET library targeting .NET Core?
How to package a .NET library targeting .NET Framework and Universal Windows Platform and include platform-specific functionality?
How to package a multi-architecture .NET library that targets the Universal Windows Platform?
How to package a .NET library that targets the Universal Windows Platform and depends on Visual Studio extension SDKs?

最佳答案

此答案基于principles used to package libraries targeting the .NET Framework。请先阅读链接的答案,以更好地理解以下内容。

首先,您必须在项目构建设置中选中“生成库布局”复选框。否则,将无法使用库导出的XAML用户控件。确保将此设置应用于所有构建配置和体系结构。

除了基本的3个资产(请参阅上面的答案),您还需要从build输出目录中打包以下其他资产:


MyUwpLibrary.pri
MyUwpLibrary子目录


要使用程序集导出的XAML用户控件,需要这些额外的资源。即使您还没有从库中导出任何XAML,也要始终包括这些资产-您可能有一天会这样做,以后要记住这将非常棘手!

要发布UWP库,您需要创建具有以下结构的NuGet程序包:

\---lib
\---uap10.0
| MyUwpLibrary.dll
| MyUwpLibrary.pdb
| MyUwpLibrary.pri
| MyUwpLibrary.xml
|
\---MyUwpLibrary
HelloWorld.xaml
MyUwpLibrary.xr.xml


如果您熟悉.NET Framework库发布,则应该看起来非常熟悉和直接。您可以将以下模板用于nuspec文件:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="3.2">
<id>Example.MyUwpLibrary</id>
<version>1.0.0</version>
<authors>Firstname Lastname</authors>
<description>Example of a UWP library that exports a user control.</description>
<dependencies>
<dependency id="Newtonsoft.Json" version="8.0.1" />
</dependencies>
</metadata>
<files>
<!-- The double wildcard will also grab all the resource files and the resource subdirectory. -->
<file src="..\bin\Release\MyUwpLibrary**" target="lib\uap10.0" />
</files>
</package>


就是这样,真的!在创建NuGet软件包之前,请记住使用Release配置来构建解决方案。有关更多详细信息,请参阅上面链接的有关打包.NET Framework库的答案。

样本库和相关打包文件为 available on GitHub。与此答案对应的解决方案是SimpleUwpLibrary。

关于.net - 如何打包针对通用Windows平台的.NET库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34611882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com