cake-contrib / Cake_Git

Cake AddIn that extends Cake with Git features using LibGit2 and LibGit2Sharp
https://cakebuild.net/extensions/cake-git
Other
39 stars 64 forks source link

Warnings when using with Frosting #137

Closed pascalberger closed 8 months ago

pascalberger commented 3 years ago

When using this addin with Frosting a warning is shown.

Warning in Visual Studio:

Warning MSB3246 Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'git2-6777db8.dll' or one of its dependencies. The module was expected to contain an assembly manifest.   Cake.Frosting.Issues.Recipe C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets  2123    

Warning when building with dotnet:

C:\Program Files\dotnet\sdk\5.0.102\Microsoft.Common.CurrentVersion.targets(2123,5): warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. Assembly file 'C:\Users\PascalBerger\.nuget\packages\cake.git\1.0.0\lib\netstandard2.0\git2-6777db8.dll' could not be opened -- PE image doesn't contain managed metadata. [C:\git\github\Cake.Issues.Recipe\Cake.Frosting.Issues.Recipe\Cake.Frosting.Issues.Recipe\Cake.Frosting.Issues.Recipe.csproj]
devlead commented 3 years 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" />
jmmorato commented 3 years ago

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:

image

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.

BlythMeister commented 3 years ago

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

jmmorato commented 3 years ago

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();
devlead commented 3 years ago

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.

bert2 commented 3 years ago

It seems like an update to Cake.Frosting 1.3.0 fixed the warning in our CI.

andreasnilsen commented 2 years ago

I'm getting this issue with Cake.Frosting 2.0.0 & Cake.Git 1.1.0, is it a regression?

nils-a commented 2 years ago

@andreasnilsen there is currently no released version of Cake.Git that is compatible with Cake (Frosting) 2.0.0, see #155.

BlythMeister commented 2 years ago

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?

mike-loux-planview commented 2 years ago

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.
aivanov-oneinc commented 2 years ago

Have the same problem

CDTR-MattConroy commented 1 year ago

As of March 2023, I am having this problem. Using Cake.Frosting 3.0.0 and Cake.Git 3.0.0.

pleonex commented 1 year ago

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...