Obfuscating and packing (nuget)

Vladimir Kovalenko 11 Reputation points
2021-03-23T16:06:11.55+00:00

Hi,

I need to perform a simple task, but I cannot see a way how to do it.

I have a solution with many projects. Project files are in SDK like format. I need to do compilation, obfuscation and then packing. The issues are as follows:

  1. When packing is triggered (GeneratePackageOnBuild), the project output (build target) is used as nuget input. And this cannot be changed.
  2. Obfuscation cannot be done into the target folder, because obfuscated assemblies would overwrite non-obfuscated ones, and non-obfuscated assemblies are needed for the compilation of the next project in line (otherwise compilation will fail). Right now we are using project references, but we would also like to replace them with nuget references. The latter would mean that we need nuget packages with non-obfuscated assemblies for compilation purposes.

We would like to use msbuild GeneratePackageOnBuild feature because it eases life very much. But in the case of obfuscation, which looks like can only be done into a separate folder or at the very end of the compilation, use of the GeneratePackageOnBuild seems impossible.

How do you set up your projects with obfuscation and packing? Any practical advice?

PS There is a kind of solution to this described in the documentation for another obfuscator (https://documentation.red-gate.com/sa7/building-your-assembly/using-smartassembly-with-msbuild/automatic-integration/process-assemblies-inside-a-nuget-package), but dotnet pack -c Release triggers rebuild, which ruins it all. And there is no equivalent flag --no-build in msbuild command line.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,415 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Dylan Zhu-MSFT 6,406 Reputation points
    2021-03-24T08:41:05.837+00:00

    Hi VladimirKovalenko,

    Maybe you can nuget.exe tool: https://learn.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-pack#options

    Best Regards, Dylan

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our * *documentation* to enable e-mail notifications if you want to receive the related email notification for this thread.**

    0 comments No comments