diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetCoreVersion.cs b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetCoreVersion.cs index a3870a9fea..8625e07406 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetCoreVersion.cs +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetCoreVersion.cs @@ -1,4 +1,3 @@ -using System.Reflection; using System.Runtime; namespace HowToDetermineDotNetVersionProgramatically; @@ -7,8 +6,8 @@ public static class DotNetCoreVersion { public static string GetNetCoreVersion() { - var assembly = typeof(GCSettings).GetTypeInfo().Assembly; - var assemblyPath = assembly.Location.Split(new[] {'/', '\\'}, StringSplitOptions.RemoveEmptyEntries); + var assembly = typeof(GCSettings).Assembly; + var assemblyPath = assembly.Location.Split(['/', '\\'], StringSplitOptions.RemoveEmptyEntries); var netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App"); if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2) diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetRuntimeVersion.cs b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetRuntimeVersion.cs index 106d2ac8a3..a9f980f6a1 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetRuntimeVersion.cs +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetRuntimeVersion.cs @@ -4,7 +4,7 @@ public static class DotNetRuntimeVersion { public static string GetDotNetRuntimeVersionsInstalled() { - var process = new Process(); + using var process = new Process(); process.StartInfo.FileName = "dotnet"; process.StartInfo.Arguments = "--list-runtimes"; process.StartInfo.RedirectStandardOutput = true; @@ -20,7 +20,7 @@ public static string GetDotNetRuntimeVersionsInstalled() { return GetDotNetRuntimeVersionsInstalled() .Split(Environment.NewLine) - .Select(x => x.Split(' ')) + .Select(x => x.Split(' ', 3)) .Where(x => x.Length == 3) .Select(x => (name: x[0], version: x[1], installPath: x[2])) .ToArray(); diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetSdkVersion.cs b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetSdkVersion.cs index 10d04fafe4..38b70ec056 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetSdkVersion.cs +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/DotNetSdkVersion.cs @@ -4,7 +4,7 @@ public static class DotNetSdkVersion { public static string GetDotNetSdkVersionsInstalled() { - var process = new Process(); + using var process = new Process(); process.StartInfo.FileName = "dotnet"; process.StartInfo.Arguments = "--list-sdks"; process.StartInfo.RedirectStandardOutput = true; @@ -19,7 +19,7 @@ public static string GetDotNetSdkVersionsInstalled() { return GetDotNetSdkVersionsInstalled() .Split(Environment.NewLine) - .Select(x => x.Split(' ')) + .Select(x => x.Split(' ', 2)) .Where(x => x.Length == 2) .Select(x => (version: x[0], installPath: x[1])) .ToArray(); diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically.csproj b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically.csproj index 6836c6808f..e0ad4b5540 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically.csproj +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramatically.csproj @@ -1,7 +1,7 @@ - net7.0 + net10.0 enable enable diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyDemo/HowToDetermineDotNetVersionProgramaticallyDemo.csproj b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyDemo/HowToDetermineDotNetVersionProgramaticallyDemo.csproj index 16fbae05c9..da722a083b 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyDemo/HowToDetermineDotNetVersionProgramaticallyDemo.csproj +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyDemo/HowToDetermineDotNetVersionProgramaticallyDemo.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net10.0 enable enable diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyDemo/Program.cs b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyDemo/Program.cs index e7acbecd92..060fe780ad 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyDemo/Program.cs +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyDemo/Program.cs @@ -6,11 +6,6 @@ using static HowToDetermineDotNetVersionProgramatically.DotNetRuntimeVersion; using static HowToDetermineDotNetVersionProgramatically.DotNetSdkVersion; -var path = "HowToDetermineDotNetVersionProgramaticallyDemo.dll"; -Console.WriteLine(GetAssemblyDotNetVersion(path)); - -Console.WriteLine(GetTargetFrameworkName()); - Console.WriteLine(GetEnvironmentVersion()); Console.WriteLine(GetFrameworkDescription()); @@ -20,64 +15,39 @@ var versionPart = parts[1]; Console.WriteLine(versionPart); +Console.WriteLine(GetTargetFrameworkName()); + +var path = Path.Combine(AppContext.BaseDirectory, "HowToDetermineDotNetVersionProgramaticallyDemo.dll"); +Console.WriteLine(GetAssemblyDotNetVersion(path)); + Console.WriteLine(GetNetCoreVersion()); Console.WriteLine(GetDotNetSdkVersionsInstalled()); -static ICollection<(string version, string installPath)> GetInstalledSdkVersionsCollection() -{ - return GetDotNetSdkVersionsInstalled() - .Split(Environment.NewLine) - .Select(x => x.Split(' ')) - .Where(x => x.Length == 2) - .Select(x => (version: x[0], installPath: x[1])) - .ToArray(); -} -foreach (var (sdkVersion, installPath) in GetInstalledSdkVersionsCollection()) +foreach (var (sdkVersion, installPath) in GetInstalledSdkVersions()) { Console.WriteLine($"SDK version: {sdkVersion} Install path: {installPath}"); } Console.WriteLine(GetDotNetRuntimeVersionsInstalled()); -static ICollection<(string name, string version, string installPath)> - GetInstalledDotNetRuntimeVersionsCollection() -{ - return GetDotNetRuntimeVersionsInstalled() - .Split(Environment.NewLine) - .Select(x => x.Split(' ')) - .Where(x => x.Length == 3) - .Select(x => (name: x[0], version: x[1], installPath: x[2])) - .ToArray(); -} -foreach (var (name, version, installPath) in GetInstalledDotNetRuntimeVersionsCollection()) +foreach (var (name, version, installPath) in GetInstalledDotNetRuntimeVersions()) { Console.WriteLine($"Runtime name: {name} Version: {version} Install path: {installPath}"); } -Console.ReadLine(); - -// output -// 7.0.0.0 -// .NETCoreApp,Version=v7.0 -// 7.0.0 -// .NET 7.0.0 +// output on .NET 10.0.10, Windows +// 10.0.10 +// .NET 10.0.10 // .NET -// 7.0.0 -// 7.0.0 - -// ... -// 7.0.100 [/usr/local/share/dotnet/sdk] +// 10.0.10 +// .NETCoreApp,Version=v10.0 +// 10.0.0.0 +// 10.0.10 // ... - -// ... -// SDK version: 7.0.100 Install path: [/usr/local/share/dotnet/sdk] +// 10.0.302 [C:\Program Files\dotnet\sdk] // ... - +// SDK version: 10.0.302 Install path: [C:\Program Files\dotnet\sdk] // ... -// Microsoft.NETCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] -// ... - +// Microsoft.NETCore.App 10.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] // ... -// Runtime name: Microsoft.NETCore.App -// Version: 7.0.1 -// Install path: [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] +// Runtime name: Microsoft.NETCore.App Version: 10.0.10 Install path: [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] // ... diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetAssemblyVersionLiveTests.cs b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetAssemblyVersionTests.cs similarity index 71% rename from csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetAssemblyVersionLiveTests.cs rename to csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetAssemblyVersionTests.cs index 24424519f9..b3048e4e78 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetAssemblyVersionLiveTests.cs +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetAssemblyVersionTests.cs @@ -1,13 +1,13 @@ namespace HowToDetermineDotNetVersionProgramaticallyTests; -public class DotNetAssemblyVersionLiveTests +public class DotNetAssemblyVersionTests { [Fact] public void GivenPathToDllBuiltWithDotNet_WhenCallingGetAssemblyDotNetVersion_ThenReturnExpectedVersion() { // Given - var path = typeof(DotNetAssemblyVersionLiveTests).Assembly.Location; - var expectedVersion = "7.0"; + var path = typeof(DotNetAssemblyVersionTests).Assembly.Location; + var expectedVersion = "10.0"; // When var actualVersion = DotNetAssemblyVersion.GetAssemblyDotNetVersion(path); diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetClrVersionLiveTests.cs b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetClrVersionTests.cs similarity index 83% rename from csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetClrVersionLiveTests.cs rename to csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetClrVersionTests.cs index 6501a1c0cf..14286f13dd 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetClrVersionLiveTests.cs +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetClrVersionTests.cs @@ -1,12 +1,12 @@ namespace HowToDetermineDotNetVersionProgramaticallyTests; -public class DotNetClrVersionLiveTests +public class DotNetClrVersionTests { [Fact] public void GivenAssemblyBuiltWithDotNet_WhenCallingGetEnvironmentVersion_ThenReturnVersion() { // Given - var expectedVersion = "7.0"; + var expectedVersion = "10.0"; // When var actualVersion = DotNetClrVersion.GetEnvironmentVersion(); @@ -19,7 +19,7 @@ public void GivenAssemblyBuiltWithDotNet_WhenCallingGetEnvironmentVersion_ThenRe public void GivenPathToDllBuiltWithDotNet_WhenCallingGetAssemblySupportedMinimumClrVersion_ThenReturnExpectedVersion() { // Given - var path = typeof(DotNetClrVersionLiveTests).Assembly.Location; + var path = typeof(DotNetClrVersionTests).Assembly.Location; var expectedVersion = "v4.0"; // When diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetCoreVersionLiveTests.cs b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetCoreVersionTests.cs similarity index 83% rename from csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetCoreVersionLiveTests.cs rename to csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetCoreVersionTests.cs index 33aa8b8a69..a6f001985a 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetCoreVersionLiveTests.cs +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetCoreVersionTests.cs @@ -1,12 +1,12 @@ namespace HowToDetermineDotNetVersionProgramaticallyTests; -public class DotNetCoreVersionLiveTests +public class DotNetCoreVersionTests { [Fact] public void GivenCurrentProcessGarbageCollectionSettings_WhenCallingGetNetCoreVersion_ThenReturnExpectedVersion() { // Given - var expectedVersion = "7.0"; + var expectedVersion = "10.0"; // When var actualVersion = DotNetCoreVersion.GetNetCoreVersion(); diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetFrameworkDescriptionLiveTests.cs b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetFrameworkDescriptionTests.cs similarity index 80% rename from csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetFrameworkDescriptionLiveTests.cs rename to csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetFrameworkDescriptionTests.cs index 628fc96a0a..d2ea966130 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetFrameworkDescriptionLiveTests.cs +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetFrameworkDescriptionTests.cs @@ -1,12 +1,12 @@ namespace HowToDetermineDotNetVersionProgramaticallyTests; -public class DotNetFrameworkDescriptionLiveTests +public class DotNetFrameworkDescriptionTests { [Fact] public void GivenAssemblyBuiltWithDotNet_WhenCallingGetFrameworkDescription_ThenReturnDescription() { // Given - var expectedDescription = ".NET 7."; + var expectedDescription = ".NET 10."; // When var actualDescription = DotNetFrameworkDescription.GetFrameworkDescription(); diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetRuntimeVersionLiveTests.cs b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetRuntimeVersionTests.cs similarity index 94% rename from csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetRuntimeVersionLiveTests.cs rename to csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetRuntimeVersionTests.cs index 92df4dd1ec..ba1d548971 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetRuntimeVersionLiveTests.cs +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetRuntimeVersionTests.cs @@ -1,6 +1,6 @@ namespace HowToDetermineDotNetVersionProgramaticallyTests; -public class DotNetRuntimeVersionLiveTests +public class DotNetRuntimeVersionTests { [Fact] public void diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetSdkVersionLiveTests.cs b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetSdkVersionTests.cs similarity index 94% rename from csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetSdkVersionLiveTests.cs rename to csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetSdkVersionTests.cs index 37c6782fe8..0b54a34efe 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetSdkVersionLiveTests.cs +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetSdkVersionTests.cs @@ -1,6 +1,6 @@ namespace HowToDetermineDotNetVersionProgramaticallyTests; -public class DotNetSdkVersionLiveTests +public class DotNetSdkVersionTests { [Fact] public void GivenPlatformWithInstalledDotNetSdks_WhenCallingGetDotNetSdkVersionsInstalled_ThenReturnInstalledSdks() diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetTargetFrameworkNameLiveTests.cs b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetTargetFrameworkNameTests.cs similarity index 95% rename from csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetTargetFrameworkNameLiveTests.cs rename to csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetTargetFrameworkNameTests.cs index e7770bdd35..0368715378 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetTargetFrameworkNameLiveTests.cs +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/DotNetTargetFrameworkNameTests.cs @@ -1,6 +1,6 @@ namespace HowToDetermineDotNetVersionProgramaticallyTests; -public class DotNetTargetFrameworkNameLiveTests +public class DotNetTargetFrameworkNameTests { /* for use in library build on .NET Framework [Fact] diff --git a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/HowToDetermineDotNetVersionProgramaticallyTests.csproj b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/HowToDetermineDotNetVersionProgramaticallyTests.csproj index eec177d094..374d1b5854 100644 --- a/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/HowToDetermineDotNetVersionProgramaticallyTests.csproj +++ b/csharp-intermediate-topics/HowToDetermineDotNetVersionProgramatically/HowToDetermineDotNetVersionProgramaticallyTests/HowToDetermineDotNetVersionProgramaticallyTests.csproj @@ -1,7 +1,7 @@ - net7.0 + net10.0 enable enable @@ -10,13 +10,13 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all