Microsoft has opened WPF since last year, and almost all WPF source codes are now open source. When learning the framework, I will make some changes, hoping to build my own version for testing. However, as a particularly large framework, building and running can not be completed directly by clicking Run in Visual Studio. It requires a lot of preparation. This article will teach you how to build WPF framework source code step by step
I dare not say that I can build the source code of each version of WPF framework in the official repository // github.com/dotnet/wpf The successful version I build is that this commit partner can try to use the method in this article. The commit that is cut first is built according to my method, and then try to update the version after success
Read this article to let you know how to build WPF framework // github.com/dotnet/wpf Source code, but it is not guaranteed that you can build successfully
The steps to build WPF are as follows:
Download the dependent libraries required for construction
Restore NuGet Package
Build C++and C # codes in order to create NuGet packages
For our domestic partners, the most problematic problem is to download and build the required libraries, which are as follows
Dotnet-sdk-5.0.100-preview.1.20155.7-win-x64.zip Install
Dotnet-runtime-5.0.0-preview.4.20220.15-win-x86.zip Install
Strawberry perl-5.28.1.1-1-win64-x64.zip to the. netcoreengnativetemp folder
Net-framework-48-ref-assemblies-0.0.0.1-win64-x64.zip to the. netcoreengnativetemp folder
Dotnet-api-docs_netcoreapp3.0-0.0.0.2-win64-x64.zip to the. netcoreengnativetemp folder
Msvcurt-c1xx--0.0.1.2-win64-x64.zip to the. netcoreengnativetemp folder
Net-framework-472-iltools-0.0.0.1-win64-x64.zip to the. netcoreengnativetemp folder
Dotnet runtime 2.1.7-win-x86.zip installation
The. netcoreengnativetemp folder mentioned above is under the user name, such as C: Userslindexi.netcoreengnativetemp folder
These files are very large. At the same time, some files will be downloaded and placed in the temporary folder of the system. If the download fails at the first time, no verification will be performed the second time, only an IO decompression error will occur. At this time, you need to clear your own system temporary folder, user temporary folder and C: Userslindex.netcoreengnativetemp folder
When building, you also need to let Visual Studio install almost all the loads that can be installed. After all, you need to build something like C++, which also requires the Visual Studio version. The minimum Visual Studio requirement is version 16.4
At present, I certainly won't say such a way at the beginning. The failure rate of local construction is too high. Even if I download all of them with ladders, I can't succeed, because one thing lies in the code built. Microsoft's partners think that the network speed is very fast, and if the download is not completed within a certain time, it is a failure. And I basically failed to download it every time. At the same time, after the failure, no verification is done next time, that is, unless I delete all of them and download again, the car may roll over because the download is not completed and the build is half completed
A simple method is to use GitHub's Action to build. Thanks to Microsoft, Microsoft has bought GitHub to support a large number of local tyrants. All children can use GitHub's Action to build code for free as long as they create GitHub accounts. The built server can choose Windows full environment server. The latest Visual Studio and all loads are installed in the server, which has complete functions. The download and installation network speed is basically 100M per second. The important thing is that such a powerful server is free of charge, and it will be executed automatically as long as the build script is written
Okay, almost the advertising expenses have been paid. Let me tell you how to use GitHub's Action to build WPF framework source code
Tell me why before you start
The first reason is the environment, because WPF code contains part of C++code, which is specially tuned to the environment. You need to install almost all the features of Visual Studio. I just rolled over here. I installed one less and then the car rolled over. But it is hard to guess that it was less installed because the prompt is very strange. Although I give Visual Studio all the functions in one sentence, I don't expect you to listen to me
The second reason is the network speed. The package to be downloaded is still a bit large. At the same time, the server to restore NuGet has no domestic source
It just happens that all GitHub actions can meet the conditions, including all environments, and the download speed is particularly fast
The way to use GitHub's Action is to create a build manifest file and place it in the. githubworkflows folder. The manifest file is in yml format, such as dotnetcore. yml file
The format of the list file is not our focus. Theoretically, the little partner can understand it after reading the code, and does not need to learn
name: . NET Core
on: [push]
jobs: build:
runs-on: windows-latest
steps: - uses: actions/ checkout@v1 - name: Install Nuget uses: nuget/ setup-nuget@v1 with: nuget-version: 5.x - name: Build run: .build.cmd -pack -ci -configuration Release -prepareMachine /p:Platform=x86
Yes, put the manifest file in the manifest folder, such as the commit method, so that WPF can be built
The above listing file is also the simplest code for WPF to build. The core code is. build.cmd - pack - ci - configuration Release - prepareMachine/p: Platform=x86. Through this code, you can call the script written by Microsoft partners to build
If you see the output in the log and build the nupkg file, the build is successful
2021-04-23T04:00:24.5493423Z Successfully created package D:awpfwpfartifactspackagesReleaseNonShippingruntime.win-x86.Microsoft. DotNet. Wpf. GitHub.5.0.0-ci.nupkg.2021-04-23T04:00:40.3376680Z Successfully created package D:awpfwpfartifactspackagesReleaseNonShippingMicrosoft. DotNet. Arcade. Wpf. Sdk.5.0.0-ci.nupkg.2021-04-23T04:00:41.1278940Z Successfully created package D:awpfwpfartifactspackagesReleaseNonShippingMicrosoft. DotNet. Wpf. GitHub.5.0.0-ci.nupkg.2021-04-23T04:00:42.2993941Z Successfully created package D:awpfwpfartifactspackagesReleaseNonShippingMicrosoft. DotNet. Wpf. ProjectTemplates.5.0.0-ci.nupkg.2021-04-23T04:00:43.0266336Z Successfully created package D:awpfwpfartifactspackagesReleaseNonShippingMicrosoft. NET. Sdk. WindowsDesktop.5.0.0-ci.nupkg.2021-04-23T04:00:45.5485389Z 2021-04-23T04:00:45.5486750Z Build succeeded.2021-04-23T04:00:45.5488608Z 0 Warning(s)2021-04-23T04:00:45.5489064Z 0 Error(s)2021-04-23T04:00:45.5489325Z 2021-04-23T04:00:45.5921119Z Time Elapsed 00:05:29.82
That is, the simplest way to build WPF is to first transfer the Fork official warehouse to its own warehouse, clone the WPF code to the local, switch the commit to the f226a72ed5302737b14984cffdd6208731244038 version, and use the Git command below to switch the commit
git checkout f226a72ed5302737b14984cffdd6208731244038
Then create a new branch and use the Git command as follows
Git checkout - b branch name
Copy the code of the above listing file, create the dotnetcore.yml file in the. git folder relative to the. git folder, and put the above listing code into the dotnetcore.yml file
Use Git to create a commit or use Visual Studio team management to create a commit and push it to your Fork warehouse. At this time, the automatic construction of GitHub's Action will be triggered
The output of the built WPF is the NuGet package, which is located in the artifactspackages folder
After the construction is successful, please try to switch the source code of WPF to the latest and try to build it
The locally built method is relatively complex. Although we can see from the above listing file, the built code only calls the script. However, the local environment needs to be built first, such as allowing Visual Studio to install all functions
The local building method is as follows
Open Visual Studio first and let Visual Studio install all the functions, especially all the C++checks
Keep local system is the latest version of Windows 10
Download the Windows Driver Kit (WDK) installation. I'm not sure if this is necessary
Build the ladder and set the global proxy
Execute the. build.cmd script through PowerShell. Be careful not to add any suffix at this time, so that you can quickly know whether the download failed in the output information
If the download fails, you will be prompted, such as decompression failure. At this time, please clear your system temporary folder, user temporary folder, and. netcoreeng folder. The. netcoreeng here is placed in the user folder, such as the C: Userslindexi.netcoreeng folder. Empty NuGet cache folder. Call git clean - xdf to empty the code file
You can find the link of the file to be downloaded through the output of the ladder. You can try to be a local agent, download it in other ways first, and then use Fiddler to simulate the path to increase the download speed
If the following code can be output, it means that the previous download tool should be completed
LINK : fatal error LNK1104: cannot open file MSVCURTD_netcore. LIB [D:awpfwpfsrcMicrosoft.DotNet.WpfsrcDirectWriteForwarderDirectWriteForwarder.vcxproj]
The above code is because the x86 mode is not specified. Run. build.cmd - pack - ci - configuration Release - prepareMachine/p: Platform=x86 on the command line to try to build
If it still fails, you can try the above command several times without doing any cleaning. Or first call git clean - xdf to clean up, and then continue to call the above command
After many attempts, you should be able to build successfully. After that, you can open Visual Studio happily and build a project separately. Of course, not all projects can be successfully built
In the commands that call the above script, there are actually the following call methods, which are used to build x86 and x64, and to build Debug and Release
build.cmd -pack -ci -configuration $(Configuration) -prepareMachine /p:Platform=$(Platform)
Please replace $(Configuration) of the above code with Debug or Release and replace $(Platform) with x86 or x64 for construction
If you can generate an official build ID, you can add the following parameters on the command line:/p: OfficialBuildId=$(BuildId). The BuildId here is $(BUILD. BUILDNUMBER) in the official warehouse. This is a parameter in Azure Pipelines. The approximate value is 20190909.1. You can give it as you like
The - ci of the above parameter is a function provided by arcade to start CI building
If you can build official open source code, you can make your own private version. After you use the above command to build, you can find the built NuGet package in the artifactspackages folder. These files can be released privately, or you can modify the ID to release them
Now Microsoft's open source protocol is very friendly, allowing partners to modify and release the source code
Although you can make your own private release, I still recommended that you bring the code to the official warehouse, and the official big man will help you see if the code is reasonable. Use your own version only when the official leaders think the code is unreasonable but they think it is necessary, or the official release is too slow
The reason is that if you use your own version, it will be difficult to merge it into your own version after the official repair of some content
This work is licensed under the Creative Commons Attribution - Noncommercial Use - Sharing in the Same Way 4.0 International License Agreement. This article was first published by [Lin Dexi] on: // blog.csdn.net/lindexi_g d 。 You are welcome to reprint, use and republish the article, but you must keep the article's signature [Lin Dexi].
-----------------------------------
If you need to enter the technical group, please add a small editor zls20210502 !