测试使用自己编译的WPF框架(本地nuget 包引用)
上一篇博客 本地编译WPF框架源码 - wuty007 - 博客园 说到自己在本地编译WPF 框架源码,并在本地 源码 的 \wpf\artifacts\packages\Debug\NonShipping 路径下打包处了 对应的 nuget包

接下来实操测试一下如何使用这些编译出来的包
一、首先为了方便看到测试的效果,我在WPF源码的Application 的静态构造函数 增加了测试代码,用于验证是否可以测试有效

二、然后就是本地编译和构建,并输出nuget包 详看:本地编译WPF框架源码 - wuty007 - 博客园
三、调用nuget包
1、创建本地的nuget 文件夹,然后将生成的.nupkg ,放到创建的nuget文件夹里边

2、为了方便看到效果,我创建一个控制台程序,注意:由于我编译出来的是基于.Net9.0的,所以依赖的版本是基于net9.0,TargetFramework 需要选择windows,才能用到wpf。由于本地编译的wpf框架是基于x86的,所以 Platforms 选择 x86
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net9.0-windows</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <UseWPF>true</UseWPF> <Platforms>x86</Platforms> </PropertyGroup> </Project>
3、vs 配置本地nuget 配置目录

4、引用本地编译的 wpf nuget包
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net9.0-windows</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <UseWPF>true</UseWPF> <Platforms>x86</Platforms> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.DotNet.Wpf.GitHub.Debug" Version="9.0.0-ci" /> <PackageReference Include="Microsoft.DotNet.Wpf.ProjectTemplates.Debug" Version="9.0.0-ci" /> <PackageReference Include="runtime.win-x86.Microsoft.DotNet.Wpf.GitHub.Debug" Version="9.0.0-ci" /> </ItemGroup> </Project>
5、编写示例代码
// See https://aka.ms/new-console-template for more information using System.Windows; class Program { [STAThread] static void Main(string[] args) { Console.WriteLine("Hello, World!"); Application app = new Application(); var window = new Window(); window.Title = "Test"; app.Run(window); Console.ReadKey(); } }
6、执行控制台程序,观察有打印出 在WPF 源码添加的测试代码,说明是有效的


浙公网安备 33010602011771号