如何判断.csproj使用.NET Project System还是Common Project System?
Great question! Let’s break this down into two clear, actionable parts: how to spot which project system your C# project uses, and who’s actually calling the shots here.
Ways to Identify the Project System
Check the
.csprojfile directly (most reliable)- New Project System (SDK-style): The file starts with
<Project Sdk="Microsoft.NET.Sdk">(or variants likeMicrosoft.NET.Sdk.Webfor web projects). It’s super streamlined—you’ll see minimal boilerplate, with key settings like<TargetFramework>net8.0</TargetFramework>instead of scattered, verbose properties. No messy<Import>statements for old MSBuild common props/targets, and almost never any<ProjectTypeGuids>entries. - Legacy Common Project System (CPS): The file opens with a basic
<Project>tag (noSdkattribute). You’ll find imports like<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />and<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />. It’ll also have explicit properties like<AssemblyName>MyLegacyProject</AssemblyName>and<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>, plus often<ProjectTypeGuids>for specialized project types (e.g., WPF/WinForms).
- New Project System (SDK-style): The file starts with
Visual Studio UI Clues
- New SDK-style projects load faster and have a simplified Properties window (with tabs like Application, Build, Debug focused on modern .NET settings). Right-clicking the project will show clean, direct options like Add > Class without clunky legacy submenus.
- Legacy CPS projects may take longer to load, have a more cluttered Properties window with classic .NET Framework settings, and might use a legacy project icon (e.g., a yellow class library instead of the modern blue .NET icon).
Command Line Build Behavior
- New SDK-style projects work seamlessly with
dotnet build/dotnet runCLI commands. Run these on a legacy CPS project, and you’ll get errors telling you to use MSBuild directly—legacy projects don’t support the .NET CLI.
- New SDK-style projects work seamlessly with
Who Controls the Project System Type?
Short answer: Your .csproj file dictates which project system Visual Studio uses—not the other way around.
Visual Studio detects the project format from the .csproj and loads the corresponding system automatically:
- If the file uses the SDK-style structure, VS fires up the new Project System.
- If it’s the legacy non-SDK format, VS falls back to the older CPS.
That said, VS version does play a small role: Older versions (pre-2019) don’t support SDK-style projects at all, but modern VS (2019+) works with both. As you noted, Microsoft is phasing out CPS, so migrating to SDK-style projects is recommended for better performance, CLI support, and long-term compatibility.
内容的提问来源于stack exchange,提问作者Turner Bass

