Options

[RESOLVED] .NET 6 Winform App with Setup & Deployment (.msi)

LPetersonLPeterson Posts: 7 New member
edited January 18, 2023 4:37PM in SmartAssembly
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>

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

  • Options
    LPetersonLPeterson Posts: 7 New member
    edited January 19, 2023 4:44AM
    To deploy a Winforms app developed using .NET 6 using the Visual Studio Installer (Setup & Deployment project), you have to trick the system via a workaround.

    1) You only need the following in your .vbproj file:

      <PropertyGroup>
        <!-- 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>

    at the bottom of the .vbproj file, you need to overwrite the assembly:

      <PropertyGroup>
        <SmartAssemblyOverwriteAssembly>true</SmartAssemblyOverwriteAssembly>
      </PropertyGroup>

    2).  Left-click on the Setup project, and then select File System Editor icon at the top of the properties ribbon of the Solution Explorer.   Next, on the left panel, right-click on the Application Folder, then select Add-->Folder.  Name the subfolder the same name as the VB project.

    3).  Select Release in the Build Configuration, and right click on the VB Project in the right panel (the solution's projects), then Rebuild (do not build the Setup project in the Solution!)

    4). Navigate to obj\Release and notice the folder "net6.0-windows".  Right click on this folder, select Copy, and then go to the new subfolder you made in Application Folder (left panel of File System Editor, of Setup project).  Then on the right panel, in the whitespace, place your mouse over the whitespace, and right-click -- Paste.

    5).  Next, double-click on the "net6.0-windows" folder, and look for the .exe file for your VB project.  Right click on it then select Create Shortcut, and do this twice to make two shortcuts.  Then click on the Desktop folder (left panel) and then in the whitespace on the right panel, right-click, then Paste the shortcut.  Repeat this for the Program File list.   Rename the shortcuts (as this is your app name that will be on the user's desktop after installation) and add the icon to each shortcut. 

    6).  Right click on the Setup project in the solution, then select Rebuild.   Then install your app by double-clicking on the .msi setup file that was generated.   Your app will now have an icon on the desktop that can be double-clicked to run.

    (for those who are using SA to obfuscate, you can confirm the .dll is obfuscated by using the following steps).

    7).  You can confirm the output .dll for your project file in the "net6.0-windows" folder is obfuscated by using a trial version of .NET Reactor.  After installation of .NET Reactor, right click on the .dll file in "net6.0-windows", then select Open with .NET Reactor, then click on the rightmost tab to view the assembly, and you can see that it's obfuscated.

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











Sign In or Register to comment.