Skip to content

Build and Deploy

damiancosmoschapman edited this page Oct 16, 2023 · 52 revisions

Home / Developer / Build and Deploy

The build and deploy setup for the C# code has changed from version 5.7.x to 6.0.0.

Build

When you build there is a dependency on the Solution configurations in Visual Studio.

For example if you want to build Test, choose the Test Solution Configuration in Visual Studio and the Test build will be built in the <ROOT_DIRECTORY>/server/PxStat/bin/Test/net6.0(where <ROOT_DIRECTORY> is the root directory of the PxStat checkout. This build will have all of the configuration files needed to run the Test build. i.e. appSettings.json, log4net.xml and web.config. These files will contain the correct settings for the Test environment.

![Test Solution Configuration](file:///Users\chapmand\Saved Games\Pictures\Saved Pictures\solutionConfiguration.png) The table shows the different build locations for the different environments based on their Solution configurations.

Environment Solution configuration Build Location
Debug Debug bin/net6.0
Demo Demo bin/Demo/net6.0
Dev Dev bin/Dev/net6.0
Live Live bin/Live/net6.0
Test Test bin/Test/net6.0
UAT UAT bin/UAT/net6.0

The build file <ROOT_DIRECTORY>/server/PxStat/PxStat.csproj, is used, to build, to all the different environments.
This .csproj file uses targets to copy or remove various configuration files to correctly build PxStat for the specific environment. For example, to build the Test environment the targets CopyTestAppSettings, RemoveAppSettings and RemoveConfig are used:

<Target Name="CopyTestAppSettings" AfterTargets="Build" Condition="'$(Configuration)'=='Test'">
    <Message Text="Copying $(Outdir)appsettings.Test.json to $(Outdir)appsettings.json" />
    <Copy SourceFiles="$(Outdir)appsettings.Test.json" DestinationFiles="$(Outdir)appsettings.json" Condition="Exists('$(Outdir)appsettings.Test.json')" />
    <Copy SourceFiles="$(Outdir)log4net.Test.config" DestinationFiles="$(Outdir)log4net.config" Condition="Exists('$(Outdir)log4net.Test.config')" />
  </Target>

The CopyTestAppSettings target will be run after the build target and is conditional on the Test Solution configuration being set in Visual Studio. $(Outdir) is a Visual Studio Build Property Macro. This corresponds to the <ROOT_DIRECTORY>/server/PxStat/bin/Test/net6.0 directory.
The Copy tag copies the <ROOT_DIRECTORY>/server/PxStat/bin/Test/net6.0/appsettings.Test.json to the <ROOT_DIRECTORY>/server/PxStat/bin/Test/net6.0/appsettings.json on condition that <ROOT_DIRECTORY>/server/PxStat/bin/Test/net6.0/appsettings.Test.json exists.
The second Copy tag copies the <ROOT_DIRECTORY>/server/PxStat/bin/Test/net6.0/log4net.Test.config to the <ROOT_DIRECTORY>/server/PxStat/bin/Test/net6.0/log4net.config on condition that <ROOT_DIRECTORY>/server/PxStat/bin/Test/net6.0/log4net.Test.config exists.

<Target Name="RemoveAppSettings" AfterTargets="Build">
    <Delete Files="$(OutDir)appsettings.Debug.json" />
    <Delete Files="$(OutDir)appsettings.Test.json" />
    <Delete Files="$(OutDir)appsettings.UAT.json" />
    <Delete Files="$(OutDir)appsettings.Demo.json" />
    <Delete Files="$(OutDir)appsettings.Live.json" />
    <Delete Files="$(OutDir)appsettings.Dev.json" />
  </Target>

The RemoveAppSettings target will be run after the build target and is used to delete unnecessary files in the build output directory. The Delete tags delete the files appsettings.Debug.json, appsettings.Test.json, appsettings.UAT.json, appsettings.Demo.json, appsettings.Live.json and appsettings.Dev.json in the build output directory.

  <Target Name="RemoveConfig" AfterTargets="Build">
    <Delete Files="$(OutDir)log4net.Live.config" />
    <Delete Files="$(OutDir)log4net.Test.config" />
    <Delete Files="$(OutDir)log4net.Demo.config" />
    <Delete Files="$(OutDir)log4net.UAT.config" />
    <Delete Files="$(OutDir)web.Live.config" />
  </Target>

The RemoveConfig target will be run after the build target and is used to delete unnecessary files in the build output directory. The Delete tags delete the files log4net.Live.config, log4net.Test.config, log4net.Demo.config, log4net.UAT.config and web.Live.config in the build output directory.

Deploy or Publish

When you deploy or publish there is a dependency on the Solution configurations in Visual Studio.

For example if you want to publish Test, choose the Test Solution in Visual Studio and the Test build will be built in the <ROOT_DIRECTORY>/server/PxStat/bin/Test/net6.0(where <ROOT_DIRECTORY> is the root directory of the PxStat checkout. This publication will have all of the configuration files needed to run the Test build. i.e. appSettings.json, log4net.xml and web.config. These files will contain the correct settings for the Test environment.

The publish file _**<ROOT_DIRECTORY>/server/PxStat/Properties/PublishProfiles/Test.pubxml, is used, to publish, to the Test environment.
The table shows the different names for the publish files for the different environments based on their Solution configurations.

Environment Solution configuration Publish Location
Demo Demo <ROOT_DIRECTORY>/server/PxStat/Properties/PublishProfiles/Demo.pubxml
Dev Dev <ROOT_DIRECTORY>/server/PxStat/Properties/PublishProfiles/Dev.pubxml
Live Live <ROOT_DIRECTORY>/server/PxStat/Properties/PublishProfiles/Live.pubxml
Test Test <ROOT_DIRECTORY>/server/PxStat/Properties/PublishProfiles/Test.pubxml
UAT UAT <ROOT_DIRECTORY>/server/PxStat/Properties/PublishProfiles/UAT.pubxml
Clone this wiki locally