@@ -22,20 +22,28 @@ public static ProductInfoHeaderValue FromFile(string path, Func<string, string>
2222 FileVersionInfo fileVersionInfo = FileVersionInfo . GetVersionInfo ( path ) ;
2323 string productName = fileVersionInfo . ProductName ;
2424 string assemblyName = Path . GetFileNameWithoutExtension ( path ) ;
25- string normalizedAssemblyName = assemblyName . Replace ( "." , null ) ;
2625 string productVersion = fileVersionInfo . ProductVersion ;
26+ return ResolveUserAgent ( productName , assemblyName , productVersion , productNameFormatter ) ;
27+ }
28+
29+ private static ProductInfoHeaderValue ResolveUserAgentFromAssembly ( Assembly assembly , Func < string , string > productNameFormatter )
30+ {
31+ string productName = assembly . GetCustomAttribute < AssemblyProductAttribute > ( ) ? . Product ;
32+ string assemblyName = assembly . GetName ( ) . Name ;
33+ string productVersion = assembly . GetCustomAttribute < AssemblyInformationalVersionAttribute > ( ) ? . InformationalVersion ;
34+ return ResolveUserAgent ( productName , assemblyName , productVersion , productNameFormatter ) ;
35+ }
2736
37+ private static ProductInfoHeaderValue ResolveUserAgent ( string productName , string assemblyName , string productVersion , Func < string , string > productNameFormatter )
38+ {
39+ string normalizedAssemblyName = assemblyName . Replace ( "." , null ) ;
2840 string userAgentProductName = $ "{ productName } { normalizedAssemblyName } ";
2941 if ( productNameFormatter != null )
3042 userAgentProductName = productNameFormatter ( userAgentProductName ) ;
3143
3244 return new ProductInfoHeaderValue ( userAgentProductName , productVersion ) ;
3345 }
3446
35- #pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
36- private static ProductInfoHeaderValue ResolveUserAgentFromAssembly ( Assembly assembly , Func < string , string > productNameFormatter ) => FromFile ( assembly . Location , productNameFormatter ) ;
37- #pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
38-
3947 private static Assembly ResolveEntryAssembly ( )
4048 {
4149 Assembly assembly = Assembly . GetEntryAssembly ( ) ;
0 commit comments