Creating solutions and projects in VS code

In this post we are going to create a new Solution containing an F# console project and a test project using the dotnet CLI in Visual Studio Code.

Open VS Code in a new folder.

Open a new Terminal window. The shortcut for this is CTRL+SHIFT+'.

Create a new file in the folder. It doesn't matter what it is called, so use 'setup.txt'.

Copy the following script into the file:

dotnet new sln -o MySolution
cd MySolution
mkdir src
dotnet new console -lang F# -o src/MyProject
dotnet sln add src/MyProject/MyProject.fsproj
mkdir tests
dotnet new xunit -lang F# -o tests/MyProjectTests
dotnet sln add tests/MyProjectTests/MyProjectTests.fsproj
cd tests/MyProjectTests
dotnet add reference ../../src/MyProject/MyProject.fsproj
dotnet add package FsUnit
dotnet add package FsUnit.XUnit
dotnet build
dotnet test

This script will create a new solution called MySolution, two folders called src and tests, a console app called MyProject in the src folder, and a test project called MyProjectTests in the tests folder. Change the names to suit. In VS Code, CTRL+F2 will allow you to edit all of the instances of a selected word at the same time.

If you want C# projects, omit the '-lang F#' from both project lines, change the file extensions to '.csproj' from '.fsproj', and remove the lines that add the FsUnit and FsUnit.XUnit NuGet packages.

Select all of the script text.

To run the script in the Terminal, you can do either of the following:

  • Choose the Terminal menu item and then select 'Run Selected Text'.

  • Press CTRL+SHIFT+P to open the Command Palette and then type 'TRSTAT'. Select the 'Terminal: Run Selected Text in Active Terminal' item.

The script will now execute in the Terminal.

You can delete the file with the script in if you want as you no longer need it.

Summary

It's slightly more complicated than doing this in Visual Studio or Rider but once you have the scripts, it's easy to reuse them. I highly recommend getting to know VS Code better.

Zurück
Zurück

How to gather data from Miro

Weiter
Weiter

Composite UI with Design System and Micro Frontends