.NET
.NET is a free and open-source, managed computer software framework for Windows, Linux, and macOS operating systems. The project is primarily developed by Microsoft employees by way of the .NET Foundation, and released under the MIT License.
Index
Dotnet
The dotnet command-line interface is a cross-platform toolchain for developing, building, running, and publishing .NET applications.
Publish
The dotnet publish command publishes the application and its dependencies to a folder for deployment to a hosting system.
Argument | Description |
---|---|
-p:PublishSingleFile=true |
Packages into a single-file executable. |
--arch |
Target architecture.x64 |
--configuration |
Build configuration.Debug Release |
--framework |
Target framework.net6.0 |
--output |
Output directory.Build |
--os |
Target operating system.win |
--self-contained |
Packages the .NET runtime with the application so the runtime doesn't need to be installed on the target machine.true false |
Worker Services
Worker services are applications that can be used to queue operations in the background, schedule operations to execute at a later time or perform processor-intensive tasks. The project template Worker Service Template
is available in Visual Studio and dotnet CLI.
Windows services are supported worker services.
- Install the NuGet package
Microsoft.Extensions.Hosting.WindowsServices
. - Modify the program to use the windows service:
IHost host = Host.CreateDefaultBuilder(args)
.UseWindowsService(options =>
{
options.ServiceName = "My Windows Service";
})
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();
})
.Build();
Once the worker service is built, the windows service can be controlled using the Service Control application.
sc.exe create "My Service" binpath="path/to/service.exe"
- Start
sc.exe start "My Service"
- Stop
sc.exe stop "My Service"
sc.exe delete "My Service"
Special Folders
Special folders are system-defined paths.
- The function
System.Environment.GetFolderPath(System.Environment.SpecialFolder)
returns the path of a special folder. - The enum
System.Environment.SpecialFolder
is a list of special folders constants.
Path | Name |
---|---|
C:/Users/<User>/Documents |
MyDocuments |
C:/Users/<User>/Pictures |
MyPictures |
C:/Users/<User>/Music |
MyMusic |
C:/Users/<User>/Videos |
MyVideos |
C:/Users/<User>/Desktop |
Desktop |
C:/Users/<User>/Favorites |
Favorites |
C:/Users/<User>/AppData/Roaming |
ApplicationData |
C:/Users/<User>/AppData/Roaming/Microsoft/Windows/Start Menu |
StartMenu |
C:/Users/<User>/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup |
Startup |
C:/Users/Public/Documents |
CommonDocuments |
C:/Users/Public/Pictures |
CommonPictures |
C:/Users/Public/Music |
CommonMusic |
C:/Users/Public/Videos |
CommonVideos |
C:/Program Files |
ProgramFiles |
C:/Program Files/Common Files |
CommonProgramFiles |
C:/ProgramData |
CommonApplicationData |
C:/ProgramData/Microsoft/Windows/Start Menu |
CommonStartMenu |
C:/ProgramData/Microsoft/Windows/Start Menu/Programs |
CommonPrograms |
C:/ProgramData/Microsoft/Windows/Start Menu/Programs/Startup |
CommonStartup |
C:/WINDOWS/ |
Windows |
C:/WINDOWS/system32 |
System |
C:/WINDOWS/fonts |
Fonts |