Tooling and Project Concepts
Project File Parts
Model the target framework value found in a C# project file.
tooling
A `.csproj` file stores project metadata such as the target framework, which guides the build tool.
Project File Parts
ProjectFileParts.cs
Replay: real traced execution (multi-file project)
using System;
class Program
{
static void Main()
{
string targetFramework = "net8.0";
bool currentLts = targetFramework == "net8.0";
string projectType = targetFramework.StartsWith("net") ? "sdk-style" : "legacy";
Console.WriteLine($"targetFramework={targetFramework}");
Console.WriteLine($"projectType={projectType}");
Console.WriteLine($"currentLts={currentLts}");
}
}
using System;
class Program
{
static void Main()
{
string targetFramework = "net6.0";
bool currentLts = targetFramework == "net8.0";
string projectType = targetFramework.StartsWith("net") ? "sdk-style" : "legacy";
Console.WriteLine($"targetFramework={targetFramework}");
Console.WriteLine($"projectType={projectType}");
Console.WriteLine($"currentLts={currentLts}");
}
}
using System;
class Program
{
static void Main()
{
string targetFramework = "net9.0";
bool currentLts = targetFramework == "net8.0";
string projectType = targetFramework.StartsWith("net") ? "sdk-style" : "legacy";
Console.WriteLine($"targetFramework={targetFramework}");
Console.WriteLine($"projectType={projectType}");
Console.WriteLine($"currentLts={currentLts}");
}
}
targetFramework ← net8.0, currentLts ← True, projectType ← sdk-style
4{5 static void Main()6 {7 string targetFramework→ net8.0 = "net8.0"; //@targetFramework="net6.0", "net9.0"8 bool currentLts→ True = targetFrameworknet8.0 == "net8.0";9 string projectType→ sdk-style = targetFrameworknet8.0.StartsWith("net") ? "sdk-style" : "legacy";1011 Console.WriteLine($"targetFramework={targetFrameworknet8.0}");12 Console.WriteLine($"projectType={projectTypesdk-style}");13 Console.WriteLine($"currentLts={currentLtsTrue}");14 }outputtargetFramework=net8.0 projectType=sdk-style currentLts=True
targetFramework ← net6.0, currentLts ← False, projectType ← sdk-style
4{5 static void Main()6 {7 string targetFramework→ net6.0 = "net6.0";8 bool currentLts→ False = targetFrameworknet6.0 == "net8.0";9 string projectType→ sdk-style = targetFrameworknet6.0.StartsWith("net") ? "sdk-style" : "legacy";1011 Console.WriteLine($"targetFramework={targetFrameworknet6.0}");12 Console.WriteLine($"projectType={projectTypesdk-style}");13 Console.WriteLine($"currentLts={currentLtsFalse}");14 }outputtargetFramework=net6.0 projectType=sdk-style currentLts=False
targetFramework ← net9.0, currentLts ← False, projectType ← sdk-style
4{5 static void Main()6 {7 string targetFramework→ net9.0 = "net9.0";8 bool currentLts→ False = targetFrameworknet9.0 == "net8.0";9 string projectType→ sdk-style = targetFrameworknet9.0.StartsWith("net") ? "sdk-style" : "legacy";1011 Console.WriteLine($"targetFramework={targetFrameworknet9.0}");12 Console.WriteLine($"projectType={projectTypesdk-style}");13 Console.WriteLine($"currentLts={currentLtsFalse}");14 }outputtargetFramework=net9.0 projectType=sdk-style currentLts=False