[Cake] 0.C# Make automated building-Overview,
0. What is Cake?
Cake, short for C # Make, is an automated building system based on C # DSL. It can be used to compile code, copy files and folders, run unit tests, compress files, and build Nuget packages.
Familiar with the famous Make friends, you should already know what kind of tools Cake is. Cake has the following features:
1. A simple DEMO
The author created a simple DEMO (cake. demo) on Github. The following is a brief introduction. The project is very simple. A Class Library Project and a test project are as follows:
1.1 download the boot script
First, download a Powershell-based boot script file build. ps1, this file is not necessary, you can directly call the cake script file), run in the directory where the project is located: Invoke-WebRequest http://cakebuild.net/download/bootstrapper/windows-OutFile build. ps1
Note: I am currently using the windows platform and the development environment is vs 2017 community:
Linux: curl-Lsfo build. sh http://cakebuild.net/download/bootstrapper/linux
Mac: curl-Lsfo build. sh http://cakebuild.net/download/bootstrapper/osx
1.2 create a Cake script
Add a text file build. cake (the file name is random, so I am lazy to adjust the cake script file specified in build. ps1. Full file: https://github.com/linianhui/cake.demo/blob/master/build.cake)
In this step, we use Cake to build the above cake. demo project. The file content is as follows:
1 /// args 2 var target = Argument("target", "default"); 3 4 5 /// build task 6 Task("build") 7 .Does(() => 8 { 9 MSBuild("./cake.demo.sln", new MSBuildSettings{10 Verbosity = Verbosity.Minimal11 });12 });13 14 15 Task("default")16 .IsDependentOn("build");17 18 19 /// run task20 RunTarget(target);
It can be said that the script is very easy to understand, and I believe that the C # basics should be very easy to understand.
OK. Let's run the build. ps1 (the first time it runs, it will download some files required by cake, which will be stored in build. the default folder specified in ps1 is the tools Folder. If you are interested, take a look at build. ps1 ). Failed. An error occurred while running!
The reason is a Demo of mine. the Tests project references the xUnit package. MSBuild fails to correctly restore the nuget package. This is not a bug, I used MSBuild of Cake to build the vs2015 project. The current environment only installs VS2017. However, we can use Cake to write a task for restoring the nuget package.
1 /// nuget task2 Task("restore-nuget-packages")3 .Does(() =>4 {5 NuGetRestore("./cake.demo.sln");6 });
Run again:
This time.
Then we add several tasks in sequence to clear the build files:
1 Task("clean")2 .Does(() =>3 {4 CleanDirectories("./src/*/bin");5 CleanDirectories("./test/*/bin");6 });
Run the unit test:
1 /// unit-test task2 Task("unit-test")3 .IsDependentOn("build")4 .Does(() =>5 {6 XUnit2("./test/*/bin/*/*.Tests.dll");7 });
Run the following command:
1.3 build. ps1
As mentioned above, this file is not a required file. Instead, it is used to download the relevant files required by Cake and set the default Cake configuration. Furthermore, we can use it to simplify the call to Cake. For example, we can pass parameters to build by passing the tasks listed above. ps1 to run the specified task (default is run by default ). For example:
Only files generated by build of the project are cleared.
2. Summary
Because Cake uses C # DSL to write scripts, it is easier for C # developers to use it than to write Powershell or other scripts.
Second, Cake is based on Roslyn and Mono, so that it can provide cross-platform automated construction, and can also run on a variety of common CI systems.
In addition, Cake provides a rich set of built-in tools and plug-ins (Cake Addins) to meet most of our automated building requirements, such as compilation, testing, packaging, and deployment.
For example, some days ago, one of my web demo projects (https://github.com/linianhui/Ids3.demo) used cake to deploy iis sites.
3. References
Make
C # Make
Cake Addins
Cake on Github
Cake on dotnet foundation
Cake. demo
Http://cakebuild.net/docs/tutorials/getting-started
Http://cakebuild.net/docs/resources/videos
Https://github.com/cake-build/example