|
| 1 | +import InstallNuGet from './content/_install-nuget.mdx'; |
| 2 | +import CSharpMain from './content/_csharp-main.mdx'; |
| 3 | +import CSharpUpdates from './content/_csharp-updates.mdx'; |
| 4 | +import InstallVpk from './content/_install_vpk.mdx'; |
| 5 | +import BuildRelease from './content/_build_release.mdx'; |
| 6 | +import Completion from './content/_completion.mdx'; |
| 7 | + |
| 8 | +# Getting Started: C# / WPF |
| 9 | +<AppliesTo win /> |
| 10 | +Get started with .NET 5+ (cross-platform) or .NET Framework. |
| 11 | + |
| 12 | +<InstallNuGet step={1}/> |
| 13 | + |
| 14 | +<FancyStep step={2}> |
| 15 | + <details> |
| 16 | + <summary> |
| 17 | + <strong>Create a Main method</strong> |
| 18 | + </summary> |
| 19 | + |
| 20 | + Though it is possible to simply put the Velopack bootstrap call within `App.xaml.cs`, we recommend creating a custom `Main` method to avoid any WPF overhead when applying updates. |
| 21 | + |
| 22 | + First, change the Build Actio of `App.xaml` to `Page` (right-click the file in Solution Explorer, select Properties, and change the Build Action). |
| 23 | + The project file should contain the following lines: |
| 24 | + ```xml |
| 25 | + <ItemGroup> |
| 26 | + <ApplicationDefinition Remove="App.xaml"/> |
| 27 | + <Page Include="App.xaml"/> |
| 28 | + </ItemGroup> |
| 29 | + ``` |
| 30 | + |
| 31 | + While editing the project file, change the StartupObject to point to your `App` class. |
| 32 | + Add the following PropertyGroup to your `.csproj` file: |
| 33 | + ```xml |
| 34 | + <PropertyGroup> |
| 35 | + <StartupObject>YourNamespace.App</StartupObject> |
| 36 | + </PropertyGroup> |
| 37 | + ``` |
| 38 | + |
| 39 | + Add a `Main` method to your `App.xaml.cs` file. It should look similar to this: |
| 40 | + ```csharp |
| 41 | + public partial class App : Application |
| 42 | + { |
| 43 | + [STAThread] |
| 44 | + private static void Main(string[] args) |
| 45 | + { |
| 46 | + App app = new(); |
| 47 | + app.InitializeComponent(); |
| 48 | + app.Run(); |
| 49 | + } |
| 50 | + // The rest of your App.xaml.cs code goes here |
| 51 | + } |
| 52 | + ``` |
| 53 | + |
| 54 | + Verify the changes by ensuring your app still starts correctly. |
| 55 | + </details> |
| 56 | +</FancyStep> |
| 57 | + |
| 58 | +<CSharpMain step={3}/> |
| 59 | + |
| 60 | +<CSharpUpdates step={4}/> |
| 61 | + |
| 62 | +<InstallVpk step={5}/> |
| 63 | + |
| 64 | +<FancyStep step={6}> |
| 65 | + <details> |
| 66 | + <summary> |
| 67 | + <strong>Publish App</strong> |
| 68 | + </summary> |
| 69 | + |
| 70 | + Before building a Velopack release, you must first build your application and publish it to a directory. |
| 71 | + |
| 72 | + For simplicity, we recommend publishing it as a [self-contained application](https://learn.microsoft.com/en-us/dotnet/core/deploying/#publish-self-contained). |
| 73 | + |
| 74 | + ```batch |
| 75 | + dotnet publish yourApp.csproj -c Release --self-contained -r win-x64 -o .\publish |
| 76 | + ``` |
| 77 | + :::tip |
| 78 | + Starting with .NET 7, the `-o`/`--output` option [can no longer be used with a solution file](https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/7.0/solution-level-output-no-longer-valid?WT.mc_id=DT-MVP-5003472). |
| 79 | + ::: |
| 80 | + |
| 81 | + :::tip |
| 82 | + Starting with .NET 8 and later, the `dotnet publish` command defaults to the Release configuration, so you can omit the `-c Release` option. |
| 83 | + For more details see https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/dotnet-publish-config. |
| 84 | + ::: |
| 85 | + |
| 86 | + :::tip |
| 87 | + If you execute the dotnet publish command from within the same directory as the .csproj file, you can omit the project argument. You can find more details on the [dotnet publish documentation](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish?WT.mc_id=DT-MVP-5003472#arguments). |
| 88 | + ::: |
| 89 | + |
| 90 | + </details> |
| 91 | +</FancyStep> |
| 92 | + |
| 93 | +<BuildRelease step={7}/> |
| 94 | + |
| 95 | +<Completion /> |
0 commit comments