diff --git a/src/coreclr/src/vm/eventreporter.cpp b/src/coreclr/src/vm/eventreporter.cpp index 3fd9cd04d8262..2ff712b1cc968 100644 --- a/src/coreclr/src/vm/eventreporter.cpp +++ b/src/coreclr/src/vm/eventreporter.cpp @@ -17,13 +17,12 @@ #include "eventreporter.h" #include "typestring.h" #include "debugdebugger.h" +#include "clrversion.h" #include #include "../dlls/mscorrc/resource.h" -#include "getproductversionnumber.h" - //--------------------------------------------------------------------------------------- // // A constructor for EventReporter. The header of the log is generated here. @@ -90,35 +89,12 @@ EventReporter::EventReporter(EventReporterType type) m_Description.Append(ssMessage); } - BOOL fHasVersion = FALSE; - DWORD dwMajorVersion = 0; - DWORD dwMinorVersion = 0; - DWORD dwBuild = 0; - DWORD dwRevision = 0; - EventReporter::GetCoreCLRInstanceProductVersion(&dwMajorVersion, &dwMinorVersion, &dwBuild, &dwRevision); - m_Description.AppendPrintf(W("%lu.%lu.%lu.%lu\n"),dwMajorVersion, dwMinorVersion, dwBuild, dwRevision); - fHasVersion = TRUE; - - if (!fHasVersion) - { - ssMessage.Clear(); - if(!ssMessage.LoadResource(CCompRC::Optional, IDS_ER_UNKNOWN)) - m_Description.Append(W("unknown\n")); - else - { - m_Description.Append(ssMessage); - m_Description.Append(W("\n")); - } - } + m_Description.Append(VER_FILEVERSION_STR_L); + m_Description.Append(W("\n")); - // Log the .NET Version if we can get it - LPCWSTR fxProductVersion = Configuration::GetKnobStringValue(W("FX_PRODUCT_VERSION")); - if (fxProductVersion != nullptr) - { - m_Description.Append(W(".NET Version: ")); - m_Description.Append(fxProductVersion); - m_Description.Append(W("\n")); - } + m_Description.Append(W(".NET Version: ")); + m_Description.Append(CLR_PRODUCT_VERSION_L); + m_Description.Append(W("\n")); ssMessage.Clear(); @@ -723,41 +699,3 @@ void DoReportForUnhandledNativeException(PEXCEPTION_POINTERS pExceptionInfo) reporter.Report(); } } - -// This function will return the product version of CoreCLR -// instance we are executing in. -void EventReporter::GetCoreCLRInstanceProductVersion(DWORD * pdwMajor, DWORD * pdwMinor, DWORD * pdwBuild, DWORD * pdwRevision) -{ - STATIC_CONTRACT_THROWS; - - // Get the instance of the runtime - HMODULE hModRuntime = GetCLRModule(); - _ASSERTE(hModRuntime != NULL); - - // Get the path to the runtime - PathString runtimePath; - DWORD ret = WszGetModuleFileName(hModRuntime, runtimePath); - if (ret != 0) - { - // Got the path - get the file version from the path - SString path; - path.Clear(); - path.Append(runtimePath); - DWORD dwVersionMS = 0; - DWORD dwVersionLS = 0; - GetProductVersionNumber(path, &dwVersionMS, &dwVersionLS); - - // Get the Major.Minor.Build.Revision details from the returned values - *pdwMajor = HIWORD(dwVersionMS); - *pdwMinor = LOWORD(dwVersionMS); - *pdwBuild = HIWORD(dwVersionLS); - *pdwRevision = LOWORD(dwVersionLS); - LOG((LF_CORDB, LL_INFO100, "GetCoreCLRInstanceVersion: Got CoreCLR version: %lu.%lu.%lu.%lu\n", - *pdwMajor, *pdwMinor, *pdwBuild, *pdwRevision)); - } - else - { - // Failed to get the path - LOG((LF_CORDB, LL_INFO100, "GetCoreCLRInstanceVersion: Unable to get CoreCLR version.\n")); - } -} diff --git a/src/coreclr/src/vm/eventreporter.h b/src/coreclr/src/vm/eventreporter.h index 4c4025f2522da..3bfede0e1e35d 100644 --- a/src/coreclr/src/vm/eventreporter.h +++ b/src/coreclr/src/vm/eventreporter.h @@ -49,8 +49,6 @@ class EventReporter // Flag to indicate if the buffer is full BOOL fBufferFull; - static void GetCoreCLRInstanceProductVersion(DWORD * pdwMajor, DWORD * pdwMinor, DWORD * pdwBuild, DWORD * pdwRevision); - public: // Construct EventReporter(EventReporterType type); diff --git a/src/installer/corehost/cli/hostpolicy/coreclr.cpp b/src/installer/corehost/cli/hostpolicy/coreclr.cpp index a619313c138ee..78a2021de05d3 100644 --- a/src/installer/corehost/cli/hostpolicy/coreclr.cpp +++ b/src/installer/corehost/cli/hostpolicy/coreclr.cpp @@ -199,7 +199,6 @@ namespace _X("APP_CONTEXT_DEPS_FILES"), _X("FX_DEPS_FILE"), _X("PROBING_DIRECTORIES"), - _X("FX_PRODUCT_VERSION"), _X("STARTUP_HOOKS"), _X("APP_PATHS"), _X("APP_NI_PATHS"), diff --git a/src/installer/corehost/cli/hostpolicy/coreclr.h b/src/installer/corehost/cli/hostpolicy/coreclr.h index 2ad2dbcc789a8..998daf4d648e1 100644 --- a/src/installer/corehost/cli/hostpolicy/coreclr.h +++ b/src/installer/corehost/cli/hostpolicy/coreclr.h @@ -62,7 +62,6 @@ enum class common_property AppContextDepsFiles, FxDepsFile, ProbingDirectories, - FxProductVersion, StartUpHooks, AppPaths, AppNIPaths, diff --git a/src/installer/corehost/cli/hostpolicy/deps_resolver.cpp b/src/installer/corehost/cli/hostpolicy/deps_resolver.cpp index 5d863a46f4ff7..21060eab4bdfb 100644 --- a/src/installer/corehost/cli/hostpolicy/deps_resolver.cpp +++ b/src/installer/corehost/cli/hostpolicy/deps_resolver.cpp @@ -590,7 +590,6 @@ void deps_resolver_t::init_known_entry_path(const deps_entry_t& entry, const pal if (m_coreclr_path.empty() && ends_with(path, DIR_SEPARATOR + pal::string_t(LIBCORECLR_NAME), false)) { m_coreclr_path = path; - m_coreclr_library_version = entry.library_version; return; } } diff --git a/src/installer/corehost/cli/hostpolicy/deps_resolver.h b/src/installer/corehost/cli/hostpolicy/deps_resolver.h index c3387fb4645b2..cb033f5c6d698 100644 --- a/src/installer/corehost/cli/hostpolicy/deps_resolver.h +++ b/src/installer/corehost/cli/hostpolicy/deps_resolver.h @@ -168,11 +168,6 @@ class deps_resolver_t return m_fx_definitions; } - const pal::string_t& get_coreclr_library_version() const - { - return m_coreclr_library_version; - } - bool is_framework_dependent() const { return m_is_framework_dependent; @@ -255,9 +250,6 @@ class deps_resolver_t // Special entry for coreclr path pal::string_t m_coreclr_path; - // Special entry for coreclr library version - pal::string_t m_coreclr_library_version; - // The filepaths for the app custom deps std::vector m_additional_deps_files; diff --git a/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp b/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp index dcaaa179dfeaa..5a0a32394e9a1 100644 --- a/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp +++ b/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp @@ -149,16 +149,6 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a ++fx_curr; } - pal::string_t clr_library_version; - if (resolver.is_framework_dependent()) - { - clr_library_version = get_root_framework(fx_definitions).get_found_version(); - } - else - { - clr_library_version = resolver.get_coreclr_library_version(); - } - // Build properties for CoreCLR instantiation pal::string_t app_base = resolver.get_app_dir(); coreclr_properties.add(common_property::TrustedPlatformAssemblies, probe_paths.tpa.c_str()); @@ -168,7 +158,6 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a coreclr_properties.add(common_property::AppContextDepsFiles, app_context_deps_str.c_str()); coreclr_properties.add(common_property::FxDepsFile, fx_deps_str.c_str()); coreclr_properties.add(common_property::ProbingDirectories, resolver.get_lookup_probe_directories().c_str()); - coreclr_properties.add(common_property::FxProductVersion, clr_library_version.c_str()); coreclr_properties.add(common_property::RuntimeIdentifier, get_current_runtime_id(true /*use_fallback*/).c_str()); bool set_app_paths = false; diff --git a/src/installer/test/Assets/TestProjects/PortableApp/Program.cs b/src/installer/test/Assets/TestProjects/PortableApp/Program.cs index 70117514e89fa..5df7e2952f8fe 100644 --- a/src/installer/test/Assets/TestProjects/PortableApp/Program.cs +++ b/src/installer/test/Assets/TestProjects/PortableApp/Program.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Runtime.InteropServices; namespace PortableApp { @@ -12,15 +13,10 @@ public static void Main(string[] args) { Console.WriteLine("Hello World!"); Console.WriteLine(string.Join(Environment.NewLine, args)); - Console.WriteLine($"Framework Version:{GetFrameworkVersionFromAppDomain()}"); + Console.WriteLine(RuntimeInformation.FrameworkDescription); // A small operation involving NewtonSoft.Json to ensure the assembly is loaded properly var t = typeof(Newtonsoft.Json.JsonReader); } - - private static string GetFrameworkVersionFromAppDomain() - { - return System.AppDomain.CurrentDomain.GetData("FX_PRODUCT_VERSION") as string; - } } } diff --git a/src/installer/test/Assets/TestProjects/SharedFxLookupPortableApp/Program.cs b/src/installer/test/Assets/TestProjects/SharedFxLookupPortableApp/Program.cs index 6c0e33b99d4a1..b4d2e65cb6aee 100644 --- a/src/installer/test/Assets/TestProjects/SharedFxLookupPortableApp/Program.cs +++ b/src/installer/test/Assets/TestProjects/SharedFxLookupPortableApp/Program.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Runtime.InteropServices; namespace SharedFxLookupPortableApp { @@ -12,15 +13,10 @@ public static void Main(string[] args) { Console.WriteLine("Hello World!"); Console.WriteLine(string.Join(Environment.NewLine, args)); - Console.WriteLine($"Framework Version:{GetFrameworkVersionFromAppDomain()}"); + Console.WriteLine(RuntimeInformation.FrameworkDescription); // A small operation involving NewtonSoft.Json to ensure the assembly is loaded properly var t = typeof(Newtonsoft.Json.JsonReader); } - - private static string GetFrameworkVersionFromAppDomain() - { - return System.AppDomain.CurrentDomain.GetData("FX_PRODUCT_VERSION") as string; - } } } diff --git a/src/installer/test/Assets/TestProjects/StandaloneApp/Program.cs b/src/installer/test/Assets/TestProjects/StandaloneApp/Program.cs index dca0b185f29bb..9e65e3b0c84f2 100644 --- a/src/installer/test/Assets/TestProjects/StandaloneApp/Program.cs +++ b/src/installer/test/Assets/TestProjects/StandaloneApp/Program.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Runtime.InteropServices; namespace StandaloneApp { @@ -12,15 +13,10 @@ public static void Main(string[] args) { Console.WriteLine("Hello World!"); Console.WriteLine(string.Join(Environment.NewLine, args)); - Console.WriteLine($"Framework Version:{GetFrameworkVersionFromAppDomain()}"); + Console.WriteLine(RuntimeInformation.FrameworkDescription); // A small operation involving NewtonSoft.Json to ensure the assembly is loaded properly var t = typeof(Newtonsoft.Json.JsonReader); } - - private static string GetFrameworkVersionFromAppDomain() - { - return System.AppDomain.CurrentDomain.GetData("FX_PRODUCT_VERSION") as string; - } } } diff --git a/src/installer/test/Assets/TestProjects/TestWindowsOsShimsApp/Program.cs b/src/installer/test/Assets/TestProjects/TestWindowsOsShimsApp/Program.cs index 23ad2c2f5d143..bc065abc49d76 100644 --- a/src/installer/test/Assets/TestProjects/TestWindowsOsShimsApp/Program.cs +++ b/src/installer/test/Assets/TestProjects/TestWindowsOsShimsApp/Program.cs @@ -13,9 +13,9 @@ public static void Main(string[] args) { Console.WriteLine("Hello World!"); Console.WriteLine(string.Join(Environment.NewLine, args)); - Console.WriteLine($"Framework Version:{GetFrameworkVersionFromAppDomain()}"); + Console.WriteLine(RuntimeInformation.FrameworkDescription); - #if WINDOWS +#if WINDOWS Version osVersion = RtlGetVersion(); if (osVersion == null) { @@ -33,12 +33,7 @@ public static void Main(string[] args) Console.WriteLine($"Reported OS version is lower than the true OS version - shims in use."); } } - #endif - } - - private static string GetFrameworkVersionFromAppDomain() - { - return System.AppDomain.CurrentDomain.GetData("FX_PRODUCT_VERSION") as string; +#endif } #if WINDOWS diff --git a/src/installer/test/HostActivation.Tests/PortableAppActivation.cs b/src/installer/test/HostActivation.Tests/PortableAppActivation.cs index 8ec51eb6e268a..0835af7398e85 100644 --- a/src/installer/test/HostActivation.Tests/PortableAppActivation.cs +++ b/src/installer/test/HostActivation.Tests/PortableAppActivation.cs @@ -263,7 +263,7 @@ public void AppHost_FrameworkDependent_Succeeds() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}"); + .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); // Verify running from within the working directory @@ -276,7 +276,7 @@ public void AppHost_FrameworkDependent_Succeeds() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}"); + .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); } [Theory] @@ -315,7 +315,7 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}"); + .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); // Verify running from within the working directory Command.Create(appExe) @@ -329,7 +329,7 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}"); + .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); } } diff --git a/src/installer/test/HostActivation.Tests/RuntimeProperties.cs b/src/installer/test/HostActivation.Tests/RuntimeProperties.cs index 6010aa24c7879..fd9edf7106192 100644 --- a/src/installer/test/HostActivation.Tests/RuntimeProperties.cs +++ b/src/installer/test/HostActivation.Tests/RuntimeProperties.cs @@ -17,27 +17,6 @@ public RuntimeProperties(RuntimeProperties.SharedTestState fixture) sharedState = fixture; } - [Fact] - public void CommonProperty_AppCanGetData() - { - var fixture = sharedState.RuntimePropertiesFixture - .Copy(); - - string name = "FX_PRODUCT_VERSION"; - string value = fixture.RepoDirProvider.MicrosoftNETCoreAppVersion; - - var dotnet = fixture.BuiltDotnet; - var appDll = fixture.TestProject.AppDll; - dotnet.Exec(appDll, name) - .EnvironmentVariable("COREHOST_TRACE", "1") - .CaptureStdErr() - .CaptureStdOut() - .Execute() - .Should().Pass() - .And.HaveStdErrContaining($"Property {name} = {value}") - .And.HaveStdOutContaining($"AppContext.GetData({name}) = {value}"); - } - [Fact] public void AppConfigProperty_AppCanGetData() { @@ -102,7 +81,7 @@ public void DuplicateCommonProperty_Fails() var fixture = sharedState.RuntimePropertiesFixture .Copy(); - string name = "FX_PRODUCT_VERSION"; + string name = "RUNTIME_IDENTIFIER"; RuntimeConfig.FromFile(fixture.TestProject.RuntimeConfigJson) .WithProperty(name, sharedState.AppTestPropertyValue) .Save(); diff --git a/src/installer/test/HostActivation.Tests/StandaloneAppActivation.cs b/src/installer/test/HostActivation.Tests/StandaloneAppActivation.cs index 6ab2ccae681ec..dac93e29407bd 100644 --- a/src/installer/test/HostActivation.Tests/StandaloneAppActivation.cs +++ b/src/installer/test/HostActivation.Tests/StandaloneAppActivation.cs @@ -42,7 +42,7 @@ public void Running_Build_Output_Standalone_EXE_with_DepsJson_and_RuntimeConfig_ .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}"); + .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); } [Fact] @@ -59,7 +59,7 @@ public void Running_Publish_Output_Standalone_EXE_with_DepsJson_and_RuntimeConfi .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}"); + .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); } [Fact] @@ -136,7 +136,7 @@ public void Running_Publish_Output_Standalone_EXE_By_Renaming_apphost_exe_Succee .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}"); + .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); } [Fact] @@ -172,7 +172,7 @@ public void Running_Publish_Output_Standalone_EXE_With_Relative_Embedded_Path_Su .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}"); + .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); } [Fact] @@ -234,7 +234,7 @@ public void Running_Publish_Output_Standalone_EXE_with_Bound_AppHost_Succeeds() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") - .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}"); + .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); } [Fact] diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.cs index a71c68131c540..d3f03d05197ce 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.cs @@ -142,10 +142,7 @@ public static Version Version { get { - // FX_PRODUCT_VERSION is expected to be set by the host - // Use AssemblyInformationalVersionAttribute as fallback if the exact product version is not specified by the host - string? versionString = AppContext.GetData("FX_PRODUCT_VERSION") as string ?? - typeof(object).Assembly.GetCustomAttribute()?.InformationalVersion; + string? versionString = typeof(object).Assembly.GetCustomAttribute()?.InformationalVersion; ReadOnlySpan versionSpan = versionString.AsSpan(); diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs index 68430979fb699..9ae9375bf3099 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs @@ -18,21 +18,15 @@ public static string FrameworkDescription { if (s_frameworkDescription == null) { - string? versionString = AppContext.GetData("FX_PRODUCT_VERSION") as string; + string? versionString = typeof(object).Assembly.GetCustomAttribute()?.InformationalVersion; - if (versionString == null) + // Strip the git hash if there is one + if (versionString != null) { - // Use AssemblyInformationalVersionAttribute as fallback if the exact product version is not specified by the host - versionString = typeof(object).Assembly.GetCustomAttribute()?.InformationalVersion; - - // Strip the git hash if there is one - if (versionString != null) + int plusIndex = versionString.IndexOf('+'); + if (plusIndex != -1) { - int plusIndex = versionString.IndexOf('+'); - if (plusIndex != -1) - { - versionString = versionString.Substring(0, plusIndex); - } + versionString = versionString.Substring(0, plusIndex); } }