gpt4 book ai didi

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

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

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

This is a series of questions and answers that document my findings on the topic of modern NuGet package authoring, focusing especially on the changes introduced with NuGet 3. You may also be interested in some related questions:

最佳答案

这个答案建立在 principles used to package libraries targeting the .NET Framework 的基础上。首先阅读链接的答案以更好地理解以下内容。

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

除了基本的 3 个 Assets (请参阅上面链接的答案)之外,您还需要从构建输出目录打包以下附加 Assets :

  • 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 包之前使用发布配置构建解决方案。有关更多详细信息,请参阅上面链接的有关打包 .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