IlRepack无法正确加载项目引用

时间:2018-08-16 07:43:35

标签: c# msbuild .net-core .net-assembly ilrepack

使用IlRepack,我正在尝试从一个项目中合并dll,该项目具有对本地dll文件的引用以及对NuGet包的引用。

这就是我在该项目的csproj文件中使用的文件(以Mono.Android为目标)

<Target Name="ILRepack" AfterTargets="Build">
    <!-- The ILRepack task will grab all build ouput assemblies
    and merge them into a single exe file for easy distribution and integration
    -->
    <ItemGroup>
      <ILRepackPackage Include="$(NuGetPackageRoot)ilrepack\*\tools\ilrepack.exe" />
      <LocalNuget Include="$(NuGetPackageRoot)localnuget\1.0.3\" />
    </ItemGroup>
    <Error Condition="!Exists(@(ILRepackPackage->'%(FullPath)'))" Text="You are trying to use the ILRepack&#xD;&#xA;     package, but it is not installed or at the correct location" />
    <Exec Command="@(ILRepackPackage->'%(fullpath)') /verbose /wildcards /lib:@(LocalNuget) /out:$(TargetDir)merged\$(AssemblyName).dll $(TargetDir)*.dll" />
  </Target>

该项目成功地将所有$(TargetDir)*.dll合并到,但是当我尝试将合并的程序集集成到xamarin解决方案中并尝试构建它时,编译器找不到LocalNuget。

Severity    Code    Description Project File    Line    Suppression State
Error       Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'LocalNuget, Version=1.0.3.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'LocalNuget'
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
   at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
   at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver)   TestMergedDllApp.Android    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets    1590    

我还尝试指定 IlRepack / lib 命令的不同变体,但到目前为止还算不错。

0 个答案:

没有答案