Open sps-nathan-alden-sr opened 2 years ago
I noticed my published application was crashing because it was attempting to read assembly metadata
Which API do you use for this:
I don't want to get distracted with that conversation since it's orthogonal to the problem here. It honestly doesn't matter how my app determines this information; what matters is the information is simply not present in the bundle executable.
That said, I am using this code, which works perfectly when the binary contains the PE information:
var version = FileVersionInfo.GetVersionInfo(Environment.ProcessPath!).ProductVersion!;
I will take a look at the issue you referenced.
It looks like there are many issues related to this exact problem. It would've been great if Microsoft had added a build error when building win-x64
on Linux as there are clearly unsupported scenarios that are never even warned about in the build logs.
@KalleOlaviNiemitalo Thanks for pointing me in the right direction. It seems I'm stuck for now--forced to use a Windows build agent for my builds.
Can you change your application to use Attribute.GetCustomAttributes, perhaps with Assembly.GetEntryAssembly? That way, the version lookup would not depend on Win32 resources.
If you instead need to publish a VERSIONINFO resource for other software to read (e.g. to let Windows Installer decide whether it should replace a file), that's harder. Some possibilities come to mind:
I had changed my code to the FileVersionInfo
method because of some information I read online about single-file executables. However, I changed my code to Assembly.GetEntryAssembly()
and tested with a published executable and it worked. So it seems I can at least mitigate the issue with this new code.
Per comment above, the SDK can't resolve this until https://github.com/dotnet/runtime/issues/3828 is fixed and we may not require any work once that's solved.
https://github.com/dotnet/runtime/issues/3828 has been fixed.
Describe the bug
I have an Azure Pipelines release pipeline for a .NET 6 console application. My build agent is a self-hosted Ubuntu 20.04 LTS server. The pipeline is installing .NET SDK 6.0.101 before executing any other steps. I am pushing published releases to GitHub. I noticed my published application was crashing because it was attempting to read assembly metadata that appears to have been stripped from the assembly during the
dotnet publish
step, which is configured to perform a self-contained publish. Because I control the build agent, I was able to perform an extensive investigation to narrow down the problem.dotnet build
Earlier in the pipeline, I perform the following
dotnet build
command:This results in an assembly being created for the console application at
~/azure-pipelines-agent/_work/2/s/artifacts/bin/Redacted.DatabaseUtilities.PostgreSql/Release/net6.0/Redacted.DatabaseUtilities.PostgreSql.dll
.I downloaded this file to my PC and opened it in Visual Studio to inspect the PE information and also JetBrains Assembly Explorer to inspect the assembly metadata:
As you can see, for the .NET assembly itself, everything is perfect.
dotnet publish
Here's where the problem lies, I believe. Here is the
dotnet publish
command as shown by the Azure Pipelines log:This results in a self-contained PE binary being created at
~/azure-pipelines-agent/_work/2/s/artifacts/bin/Redacted.DatabaseUtilities.PostgreSql/Release/net6.0/win-x64/publish/Redacted.DatabaseUtilities.PostgreSql.exe
.I downloaded this file to my PC and opened it in Visual Studio to inspect the PE information:
As you can see, there is no version information whatsoever. Windows Explorer confirms this:
Here's the strange thing: if I run
dotnet publish
on my local Windows 10 PC, the executable contains the correct PE information!I ran the same CLI command through SSH, but this time I specified
--verbosity diagnostic -bl:msbuild.binlog
. Then I downloaded the binlog and viewed it with MSBuild Structured Log Viewer. I located theGenerateSingleFileBundle
task and, inside it, theGenerateBundle
task, and found this:It appears that the file being included in the single file bundle is not the same file as the one output to
bin
bydotnet build
. I downloaded the.dll
selected in the screenshot and, sure enough, Windows Explorer shows the expected PE information is present. In other words, given the actual files being used byGenerateBundle
, I can't see how this isn't a bug.Here are some additional input parameters to the
GenerateBundle
task:Unfortunately, further behavior of
dotnet publish
is opaque to me, so I'm not sure what other information I can gather. This appears to be a bug withdotnet publish
in the context of Linux (hard for me to tell for sure).I can upload the binlog somewhere as long as it's private and secure.