1

I'm working on a C# WPF project and I need some obfuscation. I found Obfuscar and it looks very promising, using nuget and a post-build event seems like a solid solution. So I've installed the nuget package and added and tweaked the obfuscar.xml file in such a way that it should work.

However, the post build command refers to the macro $(Obfuscar), which is not recognized. Now when I build my project, I get the following build error:

The command " obfuscar.xml" exited with code 9009.

Please note the empty space after the first quotation marks: $(Obfuscar) can obviously not be resolved somehow. I tried all steps described by the docs and on other websites, including putting the macro inside quotation marks, but I just can't get it to work.

-- edit --

What I've done: - installed the Obfuscar nuget - added obfuscar.xml file with basic configuration - added post-build event - try to build

What I've tried in terms of post-build events:

$(Obfuscar) obfuscar.xml

The command " obfuscar.xml" exited with code 9009.

"$(Obfuscar)" obfuscar.xml

The command """ obfuscar.xml" exited with code 9009.

I've tried to build and run the example project and that works perfectly. I've copy-pasted the post-build event (not the xml file) from the example project to my project but that just gives the same results.

What I don't understand either is how Visual Studio could possibly know what $(Obfuscar) means or how to resolve it to the path of the Obfuscar executable. Do I need some kind of configuration for that somewhere or is it some special kind of black magic that should just work?

-- edit 2 --

I've kind of got it to work now by copying the Obfuscar executable from the nuget folder to a folder in my PATH (C:\Windows for now) as "obfuscar.exe" and simply use the post-build command obfuscar obfuscar.xml. I say kind of because actually using the nuget instead of a copied executable is that now I don't have automatic updates. Now when a new version comes out, I'll have to copy/paste it manually. Guess I'll have to add that to the readme file for now until a better solution comes up.

Mark
  • 1,258
  • 13
  • 25
  • Looking at [this answer](https://stackoverflow.com/a/53582692/109702), `$(Obfuscar)` should contain the path to your config XML file, and it should be used as a parameter for the post build command (IOW it shouldn't be the post build command by itself - you can't execute an XML file). – slugster Sep 06 '19 at 00:15
  • 1
    Thanks, I’m not trying to execute the XML though, that’s the whole point: ‘$(Obfuscar)’ just has no value while it should’ve pointed to the Obfuscar executable. – Mark Sep 06 '19 at 05:46
  • @Mark please read the whole answer that slugster linked and make sure that you followed all steps perfectly. If you did, [edit] this information to your question so people won't try to answer with things that you already tried. If any error occurs while following the steps, give proper details about the error in your question. – grek40 Sep 06 '19 at 06:12
  • Note that the `$(Obfuscator)` in different linked answers means different things. So you can't mix information from more than one answer without proper understanding. – grek40 Sep 06 '19 at 06:14
  • I'm sorry, it was really late last night when I posted the question and I was really tired. I just updated the question, thanks for pointing it out. – Mark Sep 06 '19 at 09:37
  • What if you directly use `Obfuscar.Console.exe` instead of `$(Obfuscator)`? – grek40 Sep 09 '19 at 09:08
  • I looked into it a bit and found the following: the nuget contains a file `build/obfuscar.props` with a node `$(MSBuildThisFileDirectory)..\tools\obfuscar.console.exe`. So basically, as long as the build engine processes the nuget props, it should "just work" as in `$(Obfuscar)` should be defined. – grek40 Sep 10 '19 at 20:52

1 Answers1

0

In my case the problem was that this code (in the project file):

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

was before this line (mine is VB.NET project):

<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />

I changed the order of the two fragments of XML code in the project and now it works fine.