[RESOLVED] .NET 6 Winform App with Setup & Deployment (.msi)
LPeterson
Posts: 7 New member
It appears that publishing a Setup & Deployment package (.msi) for a .NET 6 Winforms app is more complex than deploying an MSBuild for the same under .NET Framework. Thus, I have a couple questions:
1). In the VS Installer (Setup and Deployment project), I believe you need to specify the target in the Application Folder as "Published Items" and not "Primary Output." I have tried both settings with no luck. Recall, a big change for obfuscating an output from .NET 6 vs .NET Framework is that you have to create a new SA project and add the .dll assembly in \obj\Release\net6.0-windows, not the .exe, since the .exe in a .NET 6 project is a small interface that merely runs the .dll. (all your code ends up in the .dll, not the .exe). Hence, I added the .dll assembly, and then set the output to the main folder that the .sln sits in. After installing the .msi, I opened the .dll in C:\program Files\MyAppName using .NET Reactor and it was obfuscated. However, the smaller .exe which calls the .dll at run time was not there (in the installed folder). What needs to be specified as the target in the Setup project?
2). Does anyone know if the following commands in the .vbproj file are necessary for a .NET 6 Winforms app?
<TargetFramework>net6.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishReadyToRun>true</PublishReadyToRun>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<OutputType>WinExe</OutputType>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishReadyToRun>true</PublishReadyToRun>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
3). Lastly, is SA Overwrite needed at the bottom of the .vbproj file for a .NET 6 Winforms app?
<SmartAssemblyOverwriteAssembly>true</SmartAssemblyOverwriteAssembly>
The goal would be to bundle the .NET 6 framework into the .msi so Mac and Linux users will not have to install anything. Basically, I need to sort all all of the above issues and combinations/commands to get an obfuscated .NET 6. Winforms app to successfully run after installing the .msi in Windows first. Then I'll work on Mac and Linux distributions.
Answers
<!-- I have a winforms app, so i set WPF=false, and form=true-->
<UseWindowsForms>true</UseWindowsForms>
<MyType>WindowsForms</MyType>
<UseWPF>false</UseWPF>
<!-- The line below is recommended when you first use VS 2022, since it will fetch a lot of resources that are used in the project-->
<Implicitusings>enable</Implicitusings>
<!-- I turn the next line off, since I don't need the assembly file rewritten-->
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<!-- The commands below are required for .NET 6 Winform apps, to run in Windows at least-->
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup>
<SmartAssemblyOverwriteAssembly>true</SmartAssemblyOverwriteAssembly>
</PropertyGroup>
8). After installing your app in Windows, you can confirm in C:\Program Files that the .dll is the same protected file using a trial version of ".NET Reactor". (I always check that what's installed in Windows is indeed the obfuscated assembly, since this is your last chance to confirm that what's distributed is protected).