2

在 ASP.NET Core 3.1 应用程序中,obfuscar.xml 中的给定路径是正确的,但无法找到程序集/无法解析程序集

<?xml version='1.0'?>
<Obfuscator>
  <Var name="InPath" value=".\bin\Debug\netcoreapp3.1" />
  <Var name="OutPath" value="$(InPath)\publish" />
  <Var name="KeepPublicApi" value="false" />
  <Var name="HidePrivateApi" value="true" />
  <Var name="RenameProperties" value="true" />
  <Var name="RenameEvents" value="true" />
  <Var name="RenameFields" value="true" />
  <Var name="UseUnicodeNames" value="true" />
  <Var name="HideStrings" value="true" />
  <Var name="OptimizeMethods" value="true" />
  <Var name="SuppressIldasm" value="true" />
  <Module file="$(InPath)\Sample.dll" />
</Obfuscator>

构建错误:

4>Note that Rollbar API is enabled by default to collect crashes. If you want to opt out, please run with -s switch
4>Loading project .\obfuscar.xml...
4>An error occurred during processing:
4>Unable to find assembly:  .\bin\Debug\netcoreapp3.1\Sample.dll
4>Failed to resolve assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
4>G:\SomePath\Sample.csproj(110,5): error MSB3073: The command "if Debug == Debug obfuscar.console .\obfuscar.xml" exited with code 1.
4>Done building project "Sample.csproj" -- FAILED.
4

2 回答 2

3

这种组合在 netcoreapp3.1 上对我有用

构建命令

确保您使用publish以及确保将所有必要--self-contained-r依赖项复制到输出目录。

dotnet publish -c Release --self-contained=true -r win-x64 <project.csproj>

项目.csproj

  <ItemGroup>
    <Content Include="obfuscar.xml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Obfuscar">
      <Version>2.2.14</Version>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

  <PropertyGroup>
    <PostBuildEvent>$(Obfuscar) obfuscar.xml</PostBuildEvent>
  </PropertyGroup>

混淆器.xml

<?xml version='1.0'?>
<Obfuscator>
  <Var name="InPath" value="." />
  <Var name="OutPath" value=".\Obfuscator_Output" />
  <Var name="KeepPublicApi" value="true" />
  <Var name="HidePrivateApi" value="true" />
  <Var name="RenameProperties" value="true" />
  <Var name="RenameEvents" value="true" />
  <Var name="RenameFields" value="true" />
  <Var name="UseUnicodeNames" value="true" />
  <Var name="HideStrings" value="true" />
  <Var name="OptimizeMethods" value="true" />
  <Var name="SuppressIldasm" value="true" />
  <Module file="$(InPath)\Project.dll" />
</Obfuscator>
于 2020-08-06T18:23:07.453 回答
0

利用

<AssemblySearchPath path="C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\5.0.5" />
于 2021-11-13T11:53:46.977 回答