Objective
This article is mainly about using vs code for. Net Core development and the use of common CLI commands, as to why use vs code, because it is really good-looking and useful:), haha, mainly for cross-platform development to prepare.
Development environment
- Window 10
- Install. NET Core and VS Code
- C # for Visual Studio Code (powered by Omnisharp)
- Vscode-nuget-package-manager
Common commands
- Dotnet New Project (Solution, class library, unit test, etc.)
- dotnet build builds the current project
- Dotnet Run runs the current project
- Dotnet sln Add adds a new project to the solution
- dotnet Add Reference Adding a reference to a project
- dotnet Test Execution Testing
For more information, refer to the official Microsoft Note:CLI command
Here's how:
First we create a folder called Xunitdemo and open it with Vscode.
Create a solution file, open the "Integrated terminal", the default path is the directory of the current file, enter dotnet new SLn and return, as shown in the Generate a sln file with the same name as the folder
Create a new Class library project, in the current integration terminal, enter dotnet new Classlib-o demo.main,-o to specify the path to the output, as shown, creates a Demo.main folder and a. csproj file
Next we create a Service.cs class file and include a simple method for easy testing, as shown in:
CD demo.main switch to the Demo.main project path, execute the dotnet build Separate build new Demo.main class library,
The resulting path is in "demo.main\bin\debug\netstandard2.0" because the default target framework uses. NET standard2.0, and if it is. Nerframework, a different folder is generated.
Of course, we can also add multiple projects to the Xunitdemo solution, and finally build the solution.
Create the unit test project as shown in the integrated terminal input: dotnet new Test-o demo.test
Cd.. is to return to the parent directory, because we switched the path to the Demo.main folder.
Add project to Solution in dotnet sln add demo.test\demo.test.csproj demo.main\demo.main.csproj
Add Project reference Relationship,dotnet add demo.test\demo.test.csproj reference demo.main\demo.main.csproj
7. Write a simple test method and execute the test,dotnettest, as follows:
Conclusion
This article simply describes the simple process of using VS code to develop and use unit tests for. NET core, which is purely hand-crafted. On the one hand to find the feeling of writing articles, the first article of the year, the plan to write at least three blog posts per month;
Another convenience to pave the steps for subsequent. NET core articles.
Easily master vs code develop. Net Core and create Xunit unit tests