How to create an SDK-style .NET Framework project in VS?

How to create an SDK-style .NET Framework project in VS?

To create an SDK-style .NET Framework project in Visual Studio, follow these steps:

  • Open Visual Studio and create a new project.

  • In the "New Project" dialog box, select "Class Library (.NET Framework)" from the list of project templates.

  • Choose a name and location for your project, and click the "Create" button.

  • After the project is created, right-click on the project in the Solution Explorer and select "Edit Project File" from the context menu.

  • In the project file, remove the contents of the <Project> element, and replace it with the following:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net472</TargetFramework> </PropertyGroup> </Project> 

This will configure your project to use the Microsoft.NET.Sdk SDK, and target .NET Framework 4.7.2. You can adjust the TargetFramework element to target a different version of .NET Framework.

  • Save the project file and reload the project in Visual Studio.

Your project is now configured as an SDK-style .NET Framework project, and you can use the features and benefits of the SDK-style projects, such as improved package management, MSBuild-based build system, and easier migration to .NET Core.

Examples

  1. "Visual Studio create SDK-style .NET Framework project"

    <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net472</TargetFramework> </PropertyGroup> </Project> 

    Description: Basic structure of an SDK-style .NET Framework project. Specify the target framework version within the <PropertyGroup>.

  2. "Visual Studio SDK-style project with multiple target frameworks"

    <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Library</OutputType> </PropertyGroup> <PropertyGroup Condition="'$(TargetFramework)' == 'net472'"> <TargetFramework>net472</TargetFramework> </PropertyGroup> <PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'"> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> </Project> 

    Description: Defines an SDK-style project that targets both .NET Framework 4.7.2 and .NET Core 3.1.

  3. "Visual Studio SDK-style project with package references"

    <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net472</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> </ItemGroup> </Project> 

    Description: Includes a package reference to Newtonsoft.Json in the SDK-style .NET Framework project.

  4. "Visual Studio SDK-style project with assembly reference"

    <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net472</TargetFramework> </PropertyGroup> <ItemGroup> <Reference Include="System.Management" /> </ItemGroup> </Project> 

    Description: Adds a reference to the System.Management assembly in the SDK-style project.

  5. "Visual Studio SDK-style project with multiple source files"

    <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net472</TargetFramework> </PropertyGroup> <ItemGroup> <Compile Include="Program.cs" /> <Compile Include="Helper.cs" /> </ItemGroup> </Project> 

    Description: Includes multiple source files (e.g., Program.cs and Helper.cs) in the SDK-style .NET Framework project.

  6. "Visual Studio SDK-style project with preprocessor directives"

    <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net472</TargetFramework> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <DefineConstants>DEBUG;TRACE</DefineConstants> </PropertyGroup> </Project> 

    Description: Defines preprocessor directives for the Debug configuration in the SDK-style project.

  7. "Visual Studio SDK-style project with post-build events"

    <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net472</TargetFramework> </PropertyGroup> <Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Debug' "> <Exec Command="echo Post-Build Event" /> </Target> </Project> 

    Description: Configures a post-build event to echo a message in the Debug configuration.

  8. "Visual Studio SDK-style project with conditional compilation symbols"

    <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net472</TargetFramework> <DefineConstants>NET472</DefineConstants> </PropertyGroup> </Project> 

    Description: Sets conditional compilation symbols (NET472 in this example) in the SDK-style project.

  9. "Visual Studio SDK-style project with custom output path"

    <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net472</TargetFramework> <OutputPath>bin\CustomOutput</OutputPath> </PropertyGroup> </Project> 

    Description: Configures a custom output path for the SDK-style .NET Framework project.

  10. "Visual Studio SDK-style project with XML documentation file"

    <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net472</TargetFramework> <GenerateDocumentationFile>true</GenerateDocumentationFile> </PropertyGroup> </Project> 

    Description: Enables the generation of an XML documentation file in the SDK-style .NET Framework project.


More Tags

messaging hammer.js webassembly sticky sqlconnection python-3.4 workday-api django-apps cp1252 bit

More C# Questions

More Chemistry Calculators

More General chemistry Calculators

More Everyday Utility Calculators

More Financial Calculators