Article From:https://www.cnblogs.com/tylerzhou/p/9060930.html

We have just created a exe executable file with a console project in the Jenkins environment with msbuild, and if we refer to the nuget package, we can also generate it normally, but we know that we do not include these packages when we submit the project to git or SVN.When we pull the project down from GIT and open with VS, vs will first restore these nuget packages. Similarly, if we use msbuild.exe to build these projects, you also need to restore the nuget package first, otherwise the project can’t be compiled normally because of lack of dependency.Next we will introduce how to use nuget.exe to restore project dependencies.

We create a reference to Newtonsoft in the project, and then change the console to the following statement

Then we make a submission, submit it to GitHub, submit the local project after submission, and then pull it from the GitHub. The downloaded default is no Newtonsoft package (because we default overlooked when we submit it).

At this point, we will build errors in the execution command in the previous article. The output of console output is as follows

It can be seen that all errors are about Newtonsoft, as we expect, because of the lack of dependency, we can not compile the project correctly.

Next, we build a new project, a project, restore it with nuget.exe, and then use msbuild.exe to do the compilation.

We created a freestyle project, named BuildWithNuget.

Add a Execute windowsbatch command in Add Build Step.

First, we need to find the location of the nuget.exe (by windows search or everything search), and then add the restore command restore after the SLN file or csproj file to return to the original project..

After the configuration is completed, we click save and then execute Build Now.

If the configuration is no problem, a successful execution record will be generated. Click on the record to see console output. The contents are as follows

 

You can see that Newtonsoft.json.11.0.2 has been added to the specified directory. We modify the project, and then click Add Build step to add a build step under the restore nuget package, and still choose Execute windowsBatch command

Click save, execute build now

If configured correctly, a successful record will be generated to view the console output of the build record. The contents are as follows

We enter the myrelease directory under the bin directory (project specified in the myrelease directory), when you can see that the project has been correctly generated. We click on consoletest.exe to see that the object has been output from the sequence of Chinese.

Leave a Reply

Your email address will not be published. Required fields are marked *