Hexagon Geospatial
MENU

Developers Knowledge Base

WebGIS enables powerful geospatial web applications and services that securely share your organization’s rich geospatial data, and provides tools to deeply examine spatial data and create value added products, on demand.
Showing results for 
Search instead for 
Do you mean 

MSBuild Script For Creating Custom Templates.

by Technical Evangelist on ‎09-02-2015 06:44 AM - edited on ‎02-20-2019 12:46 AM by Technical Evangelist (1,195 Views)

Disclaimer

The build.xml script was created and tested with MSBuild 12.0 only. It may need to be updated if you plan to use it with later versions.

Introduction

Build.xml is a MSBuild script that compiles Geospatial Portal from the project file present in the SDK, adds language assemblies and necessary local resources and builds a "template" folder that can be then registered in the Geospatial Server Administration Console.

 

More technically:

  1. Compiles Application.csproj and its dependencies to create web application folder
  2. Copies language files to the web application folder
  3. Copies AdministratorFiles from the default template location
  4. Copies application.xml file from the default template location
  5. Updates //application/name and //application/description properties in application.xml file

After using that script for building the portal, all that needs to be done in order to use the new template is:

  • manually copying the new template from C:\MyTemplates to C:\Program Files\Common Files\Hexagon\Services\Templates\
  • registering the new template by editing C:\inetpub\wwwroot\AdminConsole\App\WorkflowSettings\AdministrationConsole.xml
  • restarting the Administration Console Service

Please make yourself familiar with Creating a new Consumer Portal template to know more technical details. Do not use this msbuild script with Consumer Portal.

Assumptions

The script assumes that:

  • it is copied to the "build" folder. Default folder structure in the package is
    • build
    • src
    • lib
  • Geospatial Server Administration Console Templates are located in
    C:\Program Files\Common Files\Hexagon\Services\Templates\Geospatial Portal\
  • The output folder for the templates is
    C:\MyTemplates
  • Script assumes that you have Visual Studio at least in 12.0 version, so:
  • You have MSBuild here:
    c:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild

Example usage

 

The following example will create a template named MyPortal from files located in C:\2015SDK\portal.

Assuming that our SDK files are in C:\2015SDK\portal folder, we need to:

  • Open the Command Line prompt:
    • Windows+R
    • cmd.exe
  • Go to the build folder
    C:\>cd \2015SDK\portal\build
  • Invoke the msbuild command
    C:\2015SDK\portal\build>"c:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild" build.xml /p:MyTemplateName=MyPortal
  • Copy your template to the Administration Console Templates folder

Copying_CustomTemplate_To_TemplatesFolder.png

 

  • After the template is ready, register it in the console:
    • Edit C:\inetpub\wwwroot\AdminConsole\App\WorkflowSettings\AdministrationConsole.xml
    • Copy Geospatial Portal WorkflowNode element
      • Give it unique 'ID', for example 1012
      • Change 'label' to MyPortal Configuration
      • The general pattern in '<TemplateName> Configuration'

Registering_Custom_Template.png

 

Restart the Admin Console Service

  • Windows+R
  • services.msc
  • Geospatial Server Administration Console
  • Restart

Restarting_Admin_Console.png

 

build.xml

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="BuildProjects">
  <Import Project="$(MSBuildThisFileDirectory)..\build\build-utilities\msbuild\main.targets" Condition="Exists('$(MSBuildThisFileDirectory)..\build\build-utilities\msbuild\main.targets')" />
  <PropertyGroup>
	<VisualStudioVersion Condition=" '$(VisualStudioVersion)'=='' ">12.0</VisualStudioVersion>
    <Configuration Condition=" '$(Configuration)'=='' ">Release</Configuration>
    <!-- Location for build output of the project -->
    <OutputRoot Condition=" '$(OutputRoot)'=='' ">$(MSBuildThisFileDirectory)..\BuildOutput\</OutputRoot>
    <!-- Root for the publish output -->
    <PublishFolder Condition=" '$(PublishFolder)'==''">C:\MyTemplates\</PublishFolder>
	<SourceTemplateFolder>C:\Program Files\Common Files\Hexagon\Services\Templates\Geospatial Portal\</SourceTemplateFolder>
  </PropertyGroup>
 
  <ItemGroup>
	<LanguageFiles Include="$(MSBuildThisFileDirectory)..\lib\language-assemblies-main-zip\application-root\**\*.*" />
	<AdministratorFiles Include="$(SourceTemplateFolder)\AdministratorFiles\**\*.*" />
    <ProjectsToBuild Include="$(MSBuildThisFileDirectory)..\src\Application\Application.csproj">
      <AdditionalProperties>
		VisualStudioVersion=$(VisualStudioVersion);
        Configuration=$(Configuration);
        OutputPath=$(OutputRoot);
        WebPublishMethod=FileSystem;
        publishUrl=$(PublishFolder)$(MyTemplateName)\Files;
        DeployOnBuild=true;
        DeployTarget=WebPublish;
        PublishProfile=$(MSBuildThisFileFullPath)
      </AdditionalProperties>
    </ProjectsToBuild>
  </ItemGroup>
 
  <Target Name="BuildProjects">
    <MSBuild Projects="@(ProjectsToBuild)" />
	<Copy SourceFiles="@(LanguageFiles)" DestinationFiles="@(LanguageFiles->'$(PublishFolder)$(MyTemplateName)\Files\%(RecursiveDir)%(Filename)%(Extension)')"/>
	<Copy SourceFiles="@(AdministratorFiles)" DestinationFiles="@(AdministratorFiles->'$(PublishFolder)$(MyTemplateName)\AdministratorFiles\%(RecursiveDir)%(Filename)%(Extension)')"/>
    <Copy SourceFiles="$(SourceTemplateFolder)\application.xml" DestinationFolder="$(PublishFolder)$(MyTemplateName)" />
	<XmlUpdate XmlFileName="$(PublishFolder)$(MyTemplateName)\application.xml"
		XPath="//application/name"
		Value="$(MyTemplateName)"
	/>
	<XmlUpdate XmlFileName="$(PublishFolder)$(MyTemplateName)\application.xml"
		XPath="//application/description"
		Value="$(MyTemplateName)"
	/>
  </Target>
 
  <Target Name="AfterWebPublish" AfterTargets="WebPublish">
    <Message Text="Inside AfterWebPublish" Importance="high"/>
  </Target>
 
</Project>

 

maketemplate.bat

For convenience you can create a bat file to launch MSBuild command:

@echo off
set msbuild="C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild"
%msbuild% /p:MyTemplateName=%1 Build.xml

Example usage:

   C:\2015SDK\portal\build\maketemplate.bat Test

 

Overview