An MSBuild Error that tells you nothing useful
winstxnhdw opened this issue · 3 comments
MSBuild Error
SOLUTION:
No need to use Fody for something like this. Simply embed the DLL as a resource in your .csproj, and then load the resource on runtime. It’s a lot more complex than it sounds without Visual Studios.
I heard Fody.Costura is able to add reference assemblies as resources. Seen at pardeike/Harmony#234. In this case, I am trying to embed the Lib.Harmony.dll into my main .DLL file.
Please check all of the platforms you are having the issue on (if platform is not listed, it is not supported)
- WPF
- UWP
- iOS
- Android
- .NET Standard
- .NET Core 6.0
Version of Library
v5.7.0 (Latest)
Version of OS(s) listed above with issue
Windows 10
Steps to Reproduce
- Install Fody
dotnet add package Fody
- Install Costura.Fody
dotnet add package Costura.Fody
- Include an Assembly into FodyWeavers.xml (or don't, it's the same)
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura IncludeAssemblies="0Harmony" />
</Weavers>
- Build the .DLL
dotnet build SomeMod
Expected Behavior
Build succeeded.
0 Warning(s)
0 Error(s)
Actual Behavior
MSBUILD : error : Fody: An unhandled exception occurred: [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : Exception: [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : Failed to execute weaver C:\Users\winston\.nuget\packages\costura.fody\5.7.0\build\..\netstandardweaver\Costura.Fody.dll [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : Type: [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : System.Exception [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : StackTrace: [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 222 [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 112 [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : Source: [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : FodyIsolated [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : TargetSite: [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : Void ExecuteWeavers() [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : Value cannot be null. (Parameter 'method') [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : Type: [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : System.ArgumentNullException [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : StackTrace: [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at Mono.Cecil.Mixin.CheckMethod(Object method) in D:\Code\Fody\cecil\Mono.Cecil\ModuleDefinition.cs:line 1276 [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at Mono.Cecil.ModuleDefinition.ImportReference(MethodReference method, IGenericParameterProvider context) in D:\Code\Fody\cecil\Mono.Cecil\ModuleDefinition.cs:line 917 [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at Mono.Cecil.ModuleDefinition.ImportReference(MethodReference method) in D:\Code\Fody\cecil\Mono.Cecil\ModuleDefinition.cs:line 912 [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at ModuleWeaver.Import(Object operand) [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at ModuleWeaver.CloneInstruction(Instruction instruction) [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at ModuleWeaver.CopyInstructions(MethodDefinition templateMethod, MethodDefinition newMethod) [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at ModuleWeaver.CopyMethod(MethodDefinition templateMethod, Boolean makePrivate) [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at ModuleWeaver.ImportAssemblyLoader(Boolean createTemporaryAssemblies) [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at ModuleWeaver.Execute() [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 186 [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : Source: [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : Mono.Cecil [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : TargetSite: [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : Void CheckMethod(System.Object) [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
MSBUILD : error : [C:\Users\winston\Desktop\Code\SomeMod\SomeMod\SomeMod.csproj]
0 Warning(s)
1 Error(s)
What sort of project is SomeMode and what sort of library is the Harmony lib (managed, unmanged, etc)?
What sort of project is SomeMode and what sort of library is the Harmony lib (managed, unmanged, etc)?
@GeertvanHorrik No idea what managed or unmanaged means, but according to this forum, I am guessing it is managed.
I am not sure what to tell you about SomeMod. It's a DLL that'll be injected into a Mono program?
Might be useful to show my .csproj here.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutDir>../bin</OutDir>
<LangVersion>latest</LangVersion>
<TargetFramework>net35</TargetFramework>
<RootNamespace>SomeMod</RootNamespace>
<ImplicitUsings>disable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>./SomeMod/References/Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>./References/UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>./References/UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="Photon3Unity3D">
<HintPath>./References/Photon3Unity3D.dll</HintPath>
</Reference>
<PackageReference Include="Fody" Version="6.6.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive; compile</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Costura.Fody" Version="5.7.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive; compile</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Lib.Harmony" Version="2.2.1" />
</ItemGroup>
</Project>
<TargetFramework>net35</TargetFramework>
This is an unsupported target framework. Also not marking the Lib.Harmony as private assets defeats the purpose of Costura.
I think it's important to understand managed vs. unmanaged first since it makes a huge difference on how to use Costura. Please read more here
Also please note that Costura is in maintenance mode and getting support is not very likely.