3

In the ASP.NET Core 3.1 app, the given path in the obfuscar.xml is correct but it is not able to find the assembly/Failed to resolve assembly:

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

The build error:

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.
John
  • 693
  • 1
  • 12
  • 37
  • 2
    Post build event is recommended in general, but for .NET Core projects, you'd better run Obfuscar on the results of `dotnet publish` (self-contained deployment should be used, as that puts all dependencies in the same folder). – Lex Li Jul 23 '20 at 15:19
  • You can add post-publish events as described here: https://curia.me/visual-studio-add-post-publish-script/ – Steve Smith Apr 16 '21 at 14:06

2 Answers2

3

This combination worked for me on netcoreapp3.1

Build Command

Make sure you use publish as well as --self-contained and -r to ensure all necessary dependencies are copied to the output directory.

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

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

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

Use

<AssemblySearchPath path="C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\5.0.5" />
afruzan
  • 1,454
  • 19
  • 20