Fix Assembly string empty on Publish

This commit is contained in:
2025-01-16 21:38:30 +01:00
parent b497117b62
commit c55592cd90
3 changed files with 30 additions and 4 deletions

View File

@ -6,7 +6,7 @@
<Authors>Glax</Authors>
<RepositoryUrl>https://github.com/C9Glax/CShocker</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<LangVersion>latestmajor</LangVersion>
<PackageProjectUrl>https://github.com/C9Glax/CShocker</PackageProjectUrl>

View File

@ -8,16 +8,30 @@ namespace CShocker.Devices.Additional;
public static class ApiHttpClient
{
internal static HttpResponseMessage MakeAPICall(HttpMethod method, string uri, string? jsonContent, ILogger? logger = null, params ValueTuple<string, string>[] customHeaders)
private static readonly ProductInfoHeaderValue UserAgent = GetUserAgent();
private static ProductInfoHeaderValue GetUserAgent()
{
Assembly assembly = Assembly.GetExecutingAssembly();
if (assembly.Location == String.Empty)
{
DirectoryInfo dir = new (AppContext.BaseDirectory);
FileInfo? f = dir.GetFiles("*.exe").FirstOrDefault();
if (f is null)
return new("CShocker", "Release");
assembly = Assembly.LoadFrom(f.FullName);
}
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
ProductInfoHeaderValue userAgent = new (fvi.ProductName ?? fvi.FileName, fvi.ProductVersion);
return new (fvi.ProductName ?? fvi.FileName, fvi.ProductVersion);
}
internal static HttpResponseMessage MakeAPICall(HttpMethod method, string uri, string? jsonContent, ILogger? logger = null, params ValueTuple<string, string>[] customHeaders)
{
HttpRequestMessage request = new (method, uri)
{
Headers =
{
UserAgent = { userAgent },
UserAgent = { UserAgent },
Accept = { new MediaTypeWithQualityHeaderValue("application/json") },
}