UWP Jenkins + NuGet + MSBuild

Source: Internet
Author: User

UWP Jenkins + NuGet + MSBuild

Background

The UWP automatic installation package is required for the project. In the past, the company came into contact with TFS for automatic build. The company asked Jenkins to do it. Don't laugh at me. I didn't know it before.

Students can check out the mistakes. If you don't, please make up your mind first. Let's take a step.

First, we have prepared two installation packages, Jenkins and NuGet, to download the latest one.

 

1. Install Jenkins. Next step. After the installation is complete, the browser will automatically jump to http: // localhost: 8080/For example

Follow the prompts to copy a GUID in the C: \ Program Files (x86) \ Jenkins \ secrets \ initialAdminPassword file, and click "Continue.

For the first time, I chose to install the recommended plug-in by default. Wait again... After that, create an account. Remember your account. I forgot my account .. It has also been reinstalled ..

If you want to reinstall it, remember to uninstall it and delete the directory C: \ Program Files (x86) \ Jenkins.

,

You can use it after filling in .. Gogo

Create a job

Select the first one and enter a name. Click OK.

To build, create an Execute Windows batch command

Copy the following code

D:\Jenkins_Test\Tools\nuget.exe restore "D:\Jenkins_Test\Projects\App1\App1.sln" -ConfigFile "C:\Users\xxxx\AppData\Roaming\NuGet\NuGet.Config" -NoCache

.

Restore is a nuget command, which means to download all the app packages required by your project D: \ Jenkins_Test \ Projects \ App1 \ App1.sln as needed. It is the same as the restoring package prompted when you use VS to compile the project.

The following-ConfigFile specifies configFlie, if not written. The default value is% AppData % \ NuGet. configIs used. Here we use the file under the xxxx account you log on to windows.

What are these commands .. For other commands, see nuget.exe-cli-reference. Remember to change xxxx to your account.

 

Next we need to create a Windows powershell. Download the powershell for jenkins plug-in.

Save and click Jenkins to return to the home page.

Click system management, select Manage INS on the right, search for Powershell under the optional ins, and select.

After the installation is complete, go back to the home page, click the newly created Test1 project again, and then click Configuration.

In this build, we chose Windows PowerShell.

Copy the following code.

# Path to Msbuild tool# $msbuild = "[Path to MsBuild.exe. See below for reference]"$msbuild = "C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe"set-alias msbuild $msbuild# solution settings# $sln_name = "[Path to Solution File. See below for reference]"$sln_name = "D:\Jenkins_Test\Projects\App1\App1.sln"$vs_config = "Release" $vs_platfom = "ARM"# call the build methodWrite-Host "Building solution`n" -foregroundcolor Greenmsbuild $sln_name /t:Build /p:Configuration=$vs_config /p:Platform=$vs_platfom /v:q /nologo

After filling in the information, we can save it. After returning the information, click build now .. For example .. Wait for the build result.

Here we will encounter the first pitfall. I am bold to indicate importance.

Build failed. We click the red ball in front .. View logs.

CSC : error CS0006: Metadata file 'C:\windows\system32\config\systemprofile\.nuget\packages\System.ComponentModel\4.0.0\ref\netcore50\System.ComponentModel.dll' could not be found [D:\Jenkins_Test\Projects\App1\ClassLibrary1\ClassLibrary1.csproj]

Pit 1

We can see that nuget store succeeded, but it ran to C: \ windows \ system32 \ config \ systemprofile \ during build \. the packpage under nuget \ packages \. Check the local folder. nuget.

However, nuget is actually under the current user's C: \ Users \ xxxx

No useful information is found on the Internet. When I view Jenkins System Management-system information, I find that the default home of Jenkins is in C: \ windows \ system32 \ config \ systemprofile, which is the default location of the local account when installing the system.

The first thing I want to do here is to change home to C: \ Users \ xxxx.

Finally, I modified the Jenkins service through this pitfall ..

Go to service and find the jenkins service. Click properties-log on to view the local account by default.

Then we need to change it to the account you logged on to the current system. Click this account, go to browse, find the account you are currently logged on to, and click OK. Remember to restart the service.

Check the jenkins system information again and you can see the home changes .. Click "create now... Wait until the build is complete ..

The ball turns blue and the compilation is successful.

In this way, the automatic compilation is completed .. In this scenario, I think the code server should automatically compile the check in to check whether the code is correct or not.

Of course, some triggers need to be written. This article does not do more research. If you are interested, you can study and communicate on your own.

 

The App package is used for testing and uploading store packages.

Create another Job, such as test2.

Create an Execute Windows batch command

Copy the following code

D:\Jenkins_Test\Tools\nuget.exe restore "D:\Jenkins_Test\Projects\App1\App1.sln" -ConfigFile "C:\Users\xxxx\AppData\Roaming\NuGet\NuGet.Config" -NoCache

Create Windows PowerShell again

# Path to Msbuild tool# $msbuild = "[Path to MsBuild.exe. See below for reference]"$msbuild = "C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe"set-alias msbuild $msbuild# solution settings# $sln_name = "[Path to Solution File. See below for reference]"$sln_name = "D:\Jenkins_Test\Projects\App1\App1\App1.csproj"# call the build methodWrite-Host "Building solution`n" -foregroundcolor Greenmsbuild $sln_name /target:Clean /target:Rebuild /target:Publish /p:Configuration=Release /p:AppxPackageDir="D:\Jenkins_Test\AppxPackages\" /p:AppxBundle=Always /p:UapAppxPackageBuildMode=StoreUpload /p:AppxBundlePlatforms="x86|x64|arm"

It is worth noting that:

1. Remember to use vs to connect the project with the necklace in the store. If it is not linked, you cannot upload the package ..

Pit 2 sln_name note that it must be a startup Item. csproj and it is. sln

Save the package and build it immediately. After that, you can find your App package in the D: \ Jenkins_Test \ AppxPackages \ folder ..

Pit3

Because the referenced package in the project does not support Any CPU, we deleted AnyCPU in the project,Note that we have deleted the sln and the AnyCPU in each sub-project..

After the deletion, we will build again, and no doubt an error is reported.

C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(724,5): error : The OutputPath property is not set for project 'ClassLibrary1.csproj'.  Please check to make sure that you have specified a valid combination of Configuration and Platform for this project.  Configuration='Debug'  Platform='AnyCPU'.  You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. [D:\Jenkins_Test\Projects\App1\ClassLibrary1\ClassLibrary1.csproj]

After studying for half a day, I found that there was no problem with the startup Item, So I compared the startup item with the project file of the sub-project.

Start item on the left and sub-project on the right

Because our sub-project has also been deleted from the AnyCPU, but the default is still using the AnyCPU item, so this leads to nuget.exe restore failure.

Since the Sub-project has no AnyCPU, we also set the default x86.
Build again after modification... Perfect! Yes ..

 

Summary

The above is how I studied Jenkins + NuGet + MSBuild to teach you how to implement automatic UWP Build and App store packages. There are a lot of pictures, and I hope to help you ..

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.