Closed pascalberger closed 8 months ago
Probably need to add LibGit2Sharp.NativeBinaries references (maybe LibGit2Sharp too) as they've got some msbuild magic in them i.e.
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0096" />
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="2.0.312" />
I would say the magic on LibGit2Sharp.NativeBinaries
has not been inherited by the Cake.Git
child.
When I take a look inside the Cake.Git package:
The native libraries are added to the main lib
folder but they should be separated by runtime. Visual Studio consider them as a reference but the native library cannot be added as an assembly and throws the warning.
i added the references and i still get the warning.
It would appear that part of internalising the libgit2sharp reference rather than it being a dependency has something not quite right
IMHO, the Cake.Git
package is not following the correct structure for netstandard native references. Surely, the root of the problem is on the libgit2sharp reference, but the workaround applied in the build.cake
script is not working correctly neither.
I did not test it, but I think it should be something like this:
diff --git a/build.cake b/build.cake
index 30da046..f34010a 100644
--- a/build.cake
+++ b/build.cake
@@ -232,14 +232,7 @@ Task("Create-NuGet-Package")
.Where(file=>file.FullPath.Contains("/linux-x64/") || file.FullPath.Contains("/win-x64/") || file.FullPath.Contains("/osx/"))
.Select(file=>new NuSpecContent {
Source = file.FullPath.Substring(artifactsRoot.FullPath.Length+1),
- Target = "lib/netstandard2.0/" + file.GetFilename()
- })
- ).Union(
- coreNative
- .Where(file=>file.FullPath.Contains("/linux-x64/") || file.FullPath.Contains("/win-x64/") || file.FullPath.Contains("/osx/"))
- .Select(file=>new NuSpecContent {
- Source = file.FullPath.Substring(artifactsRoot.FullPath.Length+1),
- Target = "lib/net5.0/" + file.GetFilename()
+ Target = "runtimes/" + file.FullPath.Substring(file.FullPath.IndexOf("/net5.0/runtimes/") + 17),
})
)
.ToArray();
Bear in mind Cake.Git was originally designed to work with how Cake script runner finds and loads assemblies. And historically some workarounds were put in place for native assemblies to load correctly. So any fix needs to be verified both with Frosting, Cake.exe (.NET Framwork 4.x) and Cake.dll (.NET Core 2.x, 3.x & .NET 5). There's most likely some better way to sort this, preferably without a nuspec and just the csproj.
It seems like an update to Cake.Frosting 1.3.0 fixed the warning in our CI.
I'm getting this issue with Cake.Frosting 2.0.0 & Cake.Git 1.1.0, is it a regression?
@andreasnilsen there is currently no released version of Cake.Git that is compatible with Cake (Frosting) 2.0.0, see #155.
Gotta love that the default nuget dependency is at least version X. Including any major version number bump 🤦♂️
Suggestion that cake libs should publish with a max version?
Still seeing this as of June 2022. Using Cake.Frosting v2.2.0 and Cake.Git v2.0.0.
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): Warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. System.BadImageFormatException: Could not load file or assembly 'git2-6777db8.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
Have the same problem
As of March 2023, I am having this problem. Using Cake.Frosting 3.0.0 and Cake.Git 3.0.0.
The issue still happening and it's affecting indirectly other modules like Cake.Frosting.Issues.Recipe
which has a reference to Cake.Git
(even when you don't want to use it and just use the Git CLI, because libgit2sharp gives so many problems with its native libs in linux distros).
Apart from causing a warning in projects (so I can't enable warnings as errors), this prevents me to write build scripts with dotnet-script in Cake.Frosting format. It fails with PE image does not have metadata.. Removing the reference to Cake.Git fixes the issue...
When using this addin with Frosting a warning is shown.
Warning in Visual Studio:
Warning when building with dotnet: