diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml
index 666a215..eb00eec 100644
--- a/.github/workflows/dev.yml
+++ b/.github/workflows/dev.yml
@@ -20,5 +20,7 @@ jobs:
path : '.'
fetch-depth: 0
- name: Cake
+ env:
+ gh-public-repos: ${{ secrets.TCOPENTEMPLATESPAT }}
run: >
.\build.ps1
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index aff13ed..ad35195 100644
--- a/.gitignore
+++ b/.gitignore
@@ -240,3 +240,7 @@ nugets/
# VSCode
.vscode/
+
+# CI/CD
+artifacts/
+.tools/
\ No newline at end of file
diff --git a/.tools/um/3.1/TcRegistry.xml b/.tools/um/3.1/TcRegistry.xml
new file mode 100644
index 0000000..9734a52
--- /dev/null
+++ b/.tools/um/3.1/TcRegistry.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+ 3.1
+
+ 1
+ C0A804010101
+ 33554432
+
+
+ .\3.1\Boot\
+ .\3.1\Config\
+ .\3.1\
+ .\3.1\Target\
+ .\3.1\Driver\AutoLoad\
+
+
+ 0
+
+
+
+
+
+ PC-WIN-U
+
+
+
diff --git a/.tools/um/Start.bat b/.tools/um/Start.bat
new file mode 100644
index 0000000..4e5539b
--- /dev/null
+++ b/.tools/um/Start.bat
@@ -0,0 +1,7 @@
+@echo off
+
+set TC_RT_INST_NETID=192.168.4.1.1.1
+set TC_RT_INST_BUILD=4024.22
+
+for %%I in (.) do set TC_INST_NAME=%%~nxI
+%TWINCAT3DIR%Runtimes\bin\Build_%TC_RT_INST_BUILD%\TcSystemServiceUm.exe -i %TC_RT_INST_NETID% -n %TC_INST_NAME% -c ".\3.1"
\ No newline at end of file
diff --git a/GitVersion.yml b/GitVersion.yml
index d9208d5..3770c90 100644
--- a/GitVersion.yml
+++ b/GitVersion.yml
@@ -1,5 +1,5 @@
mode: ContinuousDeployment
-next-version: 0.1.0
+next-version: 0.1.1
branches: {}
ignore:
sha: []
diff --git a/build.ps1 b/build.ps1
index 1a9572e..0cd4fda 100644
--- a/build.ps1
+++ b/build.ps1
@@ -1,8 +1,11 @@
-$root = Get-Location
-Set-Location .\templates\mts-s-template\
-./build.ps1
-Set-Location $root
+# dotnet run --project cake/Build.csproj -- $args
+# We need to use msbuild instead of dotnet due to COMrefs in the project.
-Set-Location .\scaffolder\TcOpen.Scaffold\
-./build.ps1
-Set-Location $root
+$msbuild =([System.Environment]::GetEnvironmentVariable('TcoMsbuild'))
+cd cake
+dotnet restore Build.csproj
+
+& $msbuild Build.csproj /t:Rebuild /p:Configuration=Release /p:Platform=AnyCPU /p:TargetFramework=net5.0 /p:DefineConstants=Release $args
+.\bin\Release\net5.0\Build.exe $args
+cd ..
+exit $LASTEXITCODE;
\ No newline at end of file
diff --git a/templates/mts-s-template/cake/Build.csproj b/cake/Build.csproj
similarity index 66%
rename from templates/mts-s-template/cake/Build.csproj
rename to cake/Build.csproj
index 8f668c6..82e4248 100644
--- a/templates/mts-s-template/cake/Build.csproj
+++ b/cake/Build.csproj
@@ -18,6 +18,14 @@
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/templates/mts-s-template/cake/BuildContext.cs b/cake/BuildContext.cs
similarity index 82%
rename from templates/mts-s-template/cake/BuildContext.cs
rename to cake/BuildContext.cs
index a4aa27c..6855461 100644
--- a/templates/mts-s-template/cake/BuildContext.cs
+++ b/cake/BuildContext.cs
@@ -1,22 +1,45 @@
-using Build;
using Cake.Core;
-using Cake.Core.Diagnostics;
using Cake.Frosting;
using EnvDTE;
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Net;
+using System.IO.Compression;
using TCatSysManagerLib;
-namespace mts_s_template
+namespace Build
{
public class BuildContext : FrostingContext
{
- public string RootRepository => Path.GetFullPath(Path.Combine(Environment.WorkingDirectory.FullPath, ".."));
- public string TemplateDirectory => Path.GetFullPath(Path.Combine(Environment.WorkingDirectory.FullPath, "../t"));
+
+ public bool CleanEnabled { get; private set; }
- public string TemplateTestsDirectory => Path.GetFullPath(Path.Combine(TemplateDirectory, "tests"));
+ public void ZipFolder(string sourceFolder, string destinationFile)
+ {
+ var outputDirectory = new FileInfo(destinationFile).Directory;
+
+ if (!outputDirectory.Exists)
+ {
+ outputDirectory.Create();
+ }
+
+ System.IO.Compression.ZipFile.CreateFromDirectory(sourceFolder, destinationFile);
+ }
+
+ private readonly string _artifactsFolder;
+ private readonly string _toolsFolder;
+
+ public string ArtifactsFolder => _artifactsFolder;
+
+ public string ToolsFolder => _toolsFolder;
+
+ public string ProjectRootDirectory { get; set; }
+ public string TemplateDirectory => System.IO.Path.Combine(ProjectRootDirectory, "t");
+
+ public string TemplateTestsDirectory => System.IO.Path.GetFullPath(System.IO.Path.Combine(TemplateDirectory, "tests"));
public IEnumerable TemplateTestFiles => Directory.EnumerateFiles(TemplateTestsDirectory, "*test*.dll", SearchOption.AllDirectories)
.Concat(Directory.EnumerateFiles(TemplateTestsDirectory, "*Test*.dll", SearchOption.AllDirectories));
@@ -32,7 +55,7 @@ public void RunIvc(string solutionFile)
EnvDTE.DTE dte = GetVsInstance(solutionFile);
var solutionFileInfo = new FileInfo(solutionFile).Directory;
- var pathToIvc = Path.Combine(solutionFileInfo.FullName, "_Vortex\\builder\\vortex.compiler.console.exe");
+ var pathToIvc = System.IO.Path.Combine(solutionFileInfo.FullName, "_Vortex\\builder\\vortex.compiler.console.exe");
// var vsProcess = ProcessRunner.Start($"{Environment.GetEnvironmentVariable("TcoDevenv")}", new Cake.Core.IO.ProcessSettings() { Arguments = $"{solutionFile}" });
var ivcProcess = ProcessRunner.Start(pathToIvc, new Cake.Core.IO.ProcessSettings() { Arguments = $"-s {solutionFile}" });
@@ -141,6 +164,7 @@ private EnvDTE80.DTE2 GetVsInstance(string solutionPath)
return DTE;
}
+
public void Clean()
{
// Clean directories
@@ -152,11 +176,12 @@ public void Clean()
.Concat(Directory.EnumerateDirectories(TemplateDirectory, "_meta", SearchOption.AllDirectories))
.ToList().ForEach(dir => { Directory.Delete(dir, true); });
}
-
+
public BuildContext(ICakeContext context)
: base(context)
{
-
- }
+ _artifactsFolder = Path.GetFullPath(Path.Combine(Environment.WorkingDirectory.FullPath, "..//artifacts"));
+ _toolsFolder = Path.GetFullPath(Path.Combine(Environment.WorkingDirectory.FullPath, "..//.tools"));
+ }
}
}
diff --git a/cake/DefaultTask.cs b/cake/DefaultTask.cs
new file mode 100644
index 0000000..0b9498e
--- /dev/null
+++ b/cake/DefaultTask.cs
@@ -0,0 +1,13 @@
+using Cake.Frosting;
+using System;
+using System.Linq;
+
+namespace Build
+{
+ [TaskName("Default")]
+ [IsDependentOn(typeof(Scaffolder.LastTask))]
+ public class DefaultTask : FrostingTask
+ {
+
+ }
+}
diff --git a/cake/Program.cs b/cake/Program.cs
new file mode 100644
index 0000000..964f465
--- /dev/null
+++ b/cake/Program.cs
@@ -0,0 +1,24 @@
+using Cake.Common.Tools.MSBuild;
+using Cake.Core;
+using Cake.Core.IO;
+using Cake.Frosting;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Cake.Common.Tools.DotNet;
+
+
+namespace Build
+{
+ public static class Program
+ {
+ public static int Main(string[] args)
+ {
+ return new CakeHost()
+ .UseContext()
+ .Run(args);
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/templates/mts-s-template/cake/ROT.cs b/cake/Utils/ROTAccess.cs
similarity index 100%
rename from templates/mts-s-template/cake/ROT.cs
rename to cake/Utils/ROTAccess.cs
diff --git a/cake/scaffolder/Scaffolder.cs b/cake/scaffolder/Scaffolder.cs
new file mode 100644
index 0000000..dedf3ea
--- /dev/null
+++ b/cake/scaffolder/Scaffolder.cs
@@ -0,0 +1,145 @@
+using Cake.Common.Tools.DotNet;
+using Cake.Core;
+using Cake.Frosting;
+using Octokit;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Build.Scaffolder
+{
+ public class Const
+ {
+ public const string BuildGroupName = " : Scaffolder";
+ }
+
+ [TaskName("Startup" + Const.BuildGroupName)]
+ [IsDependentOn(typeof(mts_s_template.LastTask))]
+ public sealed class StartUpTask : FrostingTask
+ {
+ public override void Run(BuildContext context)
+ {
+
+ }
+ }
+
+ [TaskName("Setup" + Const.BuildGroupName)]
+ [IsDependentOn(typeof(StartUpTask))]
+ public sealed class SetupTask : FrostingTask
+ {
+ public override void Run(BuildContext context)
+ {
+ context.ProjectRootDirectory = Path.GetFullPath(Path.Combine(context.Environment.WorkingDirectory.FullPath, "..//scaffolder//TcOpen.Scaffold"));
+ }
+ }
+
+ [TaskName("Clean" + Const.BuildGroupName)]
+ [IsDependentOn(typeof(SetupTask))]
+ public sealed class CleanTask : FrostingTask
+ {
+ public override void Run(BuildContext context)
+ {
+ context.ProjectRootDirectory = Path.GetFullPath(Path.Combine(context.Environment.WorkingDirectory.FullPath, "..//scaffolder//TcOpen.Scaffold"));
+ // delete artifacts folder
+ var artifactsFolder = context.FileSystem.GetDirectory(context.ArtifactsFolder);
+ if (artifactsFolder.Exists)
+ {
+ artifactsFolder.Delete(true);
+ }
+
+ context.DotNetClean($"{context.ProjectRootDirectory}\\TcOpen.Scaffold.sln");
+ }
+ }
+
+ [TaskName("Build" + Const.BuildGroupName)]
+ [IsDependentOn(typeof(CleanTask))]
+ public sealed class BuildTask : FrostingTask
+ {
+ public override void Run(BuildContext context)
+ {
+ context.DotNetBuild($"{context.ProjectRootDirectory}\\TcOpen.Scaffold.sln", new Cake.Common.Tools.DotNet.Build.DotNetBuildSettings()
+ {
+ Configuration = "Release"
+ });
+ }
+ }
+
+ [TaskName("Create artifacts" + Const.BuildGroupName)]
+ [IsDependentOn(typeof(BuildTask))]
+ public sealed class ArtifactTask : FrostingTask
+ {
+ public override void Run(BuildContext context)
+ {
+ PublishArtifact(context, "net5.0-windows", "TcOpen.Scaffold.UI.zip", $"{context.ProjectRootDirectory}\\src\\TcOpen.Scaffold.UI\\TcOpen.Scaffold.UI.csproj", $"{context.ProjectRootDirectory}\\src\\TcOpen.Scaffold.UI\\Publish");
+ PublishArtifact(context, "net5.0", "TcOpen.Scaffold.Runner.zip", $"{context.ProjectRootDirectory}\\src\\TcOpen.Scaffold.Runner\\TcOpen.Scaffold.Runner.csproj", $"{context.ProjectRootDirectory}\\src\\TcOpen.Scaffold.Runner\\Publish");
+ }
+
+ private static void PublishArtifact(BuildContext context,
+ string framework,
+ string name,
+ string projectFile,
+ string outputFolder)
+ {
+
+ context.DotNetPublish(projectFile,
+ new Cake.Common.Tools.DotNet.Publish.DotNetPublishSettings()
+ {
+ Configuration = "Release",
+ Framework = framework ,
+ PublishSingleFile = true,
+ SelfContained = false,
+ PublishReadyToRun = true,
+ Runtime = "win10-x64",
+ OutputDirectory = outputFolder
+ });
+
+ context.ZipFolder(outputFolder, Path.GetFullPath(Path.Combine(context.ArtifactsFolder, name)));
+ }
+ }
+
+ [TaskName("Publish release" + Const.BuildGroupName)]
+ [IsDependentOn(typeof(ArtifactTask))]
+ public sealed class PublishReleaseTask : FrostingTask
+ {
+ public override void Run(BuildContext context)
+ {
+ //var githubActionsProvider = new Cake.Common.Build.GitHubActions.GitHubActionsProvider(context.Environment, context.FileSystem);
+
+ //if (GitVersionInformation.BranchName == "dev")
+ {
+ var githubToken = context.Environment.GetEnvironmentVariable("gh-public-repos");
+ var githubClient = new GitHubClient(new ProductHeaderValue("TcOpen.Scaffold.UI"));
+ githubClient.Credentials = new Credentials(githubToken);
+
+ var release = githubClient.Repository.Release.Create(
+ "TcOpenGroup",
+ "tcopen-app-templates",
+ new NewRelease($"{GitVersionInformation.SemVer}")
+ {
+ Name = $"{GitVersionInformation.SemVer}",
+ TargetCommitish = GitVersionInformation.Sha,
+ Body = $"Release v{GitVersionInformation.SemVer}",
+ Draft = true,
+ Prerelease = true
+ }
+ ).Result;
+
+
+ foreach (var artifact in Directory.EnumerateFiles(context.ArtifactsFolder, "*.zip").Select(p => new FileInfo(p)))
+ {
+ var asset = new ReleaseAssetUpload(artifact.Name, "application/zip", new StreamReader(artifact.FullName).BaseStream, TimeSpan.FromSeconds(3600));
+ githubClient.Repository.Release.UploadAsset(release, asset).Wait();
+ }
+ }
+ }
+ }
+
+ [TaskName("Default" + Const.BuildGroupName)]
+ [IsDependentOn(typeof(PublishReleaseTask))]
+ public class LastTask : FrostingTask
+ {
+ }
+}
diff --git a/templates/mts-s-template/cake/Program.cs b/cake/templates/mts-s-template/mts_s_template.cs
similarity index 52%
rename from templates/mts-s-template/cake/Program.cs
rename to cake/templates/mts-s-template/mts_s_template.cs
index d31c60a..44ca23f 100644
--- a/templates/mts-s-template/cake/Program.cs
+++ b/cake/templates/mts-s-template/mts_s_template.cs
@@ -1,40 +1,59 @@
+using Build;
+using Cake.Common.Tools.DotNet;
using Cake.Common.Tools.MSBuild;
using Cake.Core;
+using Cake.Common;
using Cake.Core.IO;
using Cake.Frosting;
+using Cake.Cli;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
-namespace mts_s_template
+namespace Build.mts_s_template
{
- public static class Program
+ public class Const
{
- public static int Main(string[] args)
+ public const string BuildGroupName = " : mts-s-template";
+ }
+
+ [TaskName("Setup" + Const.BuildGroupName)]
+ public sealed class SetupTask : FrostingTask
+ {
+ public override void Run(BuildContext context)
{
- return new CakeHost()
- .UseContext()
- .Run(args);
+ context.ProjectRootDirectory = System.IO.Path.GetFullPath(System.IO.Path.Combine(context.Environment.WorkingDirectory.FullPath, "..//templates//mts-s-template"));
}
}
- [TaskName("Clean")]
+ [TaskName("Clean" + Const.BuildGroupName)]
+ [IsDependentOn(typeof(SetupTask))]
public sealed class CleanTask : FrostingTask
{
public override void Run(BuildContext context)
- {
- context.Clean();
+ {
+ if(context.Arguments.HasArgument("clean") && context.Argument("clean"))
+ {
+ context.Clean();
+ }
+ else
+ {
+
+ }
}
}
- [TaskName("Restore")]
+ [TaskName("Restore" + Const.BuildGroupName)]
[IsDependentOn(typeof(CleanTask))]
public sealed class RestoreTask : FrostingTask
{
// Tasks can be asynchronous
public override void Run(BuildContext context)
{
+ context.ProjectRootDirectory = System.IO.Path.GetFullPath(System.IO.Path.Combine(context.Environment.WorkingDirectory.FullPath, "../templates/mts-s-template/"));
foreach (var projectFile in context.TemplateProjects)
{
context.RestorePackages(projectFile);
@@ -43,13 +62,19 @@ public override void Run(BuildContext context)
}
}
- [TaskName("IvcBuild")]
+ [TaskName("IvcBuild" + Const.BuildGroupName)]
[IsDependentOn(typeof(RestoreTask))]
public sealed class IvcBuildTask : FrostingTask
{
// Tasks can be asynchronous
public override void Run(BuildContext context)
{
+ var cupdater = context.TemplateProjects.Where(p => new FileInfo(p).Name == "cupdater.csproj").FirstOrDefault();
+ var settings = new Cake.Common.Tools.DotNet.MSBuild.DotNetMSBuildSettings();
+ settings.Properties.Add("SolutionDir", new List() { new FileInfo(context.TemplateSolutions.FirstOrDefault()).DirectoryName + "\\" });
+
+ context.DotNetBuild(cupdater, new Cake.Common.Tools.DotNet.Build.DotNetBuildSettings() { MSBuildSettings = settings });
+
foreach (var solutionFile in context.TemplateSolutions)
{
context.RunIvc(solutionFile);
@@ -58,7 +83,7 @@ public override void Run(BuildContext context)
}
}
- [TaskName("Build")]
+ [TaskName("Build" + Const.BuildGroupName)]
[IsDependentOn(typeof(IvcBuildTask))]
public sealed class BuildTask : FrostingTask
{
@@ -73,33 +98,36 @@ public override void Run(BuildContext context)
}
}
- [TaskName("Test")]
+ [TaskName("Test" + Const.BuildGroupName)]
[IsDependentOn(typeof(BuildTask))]
[ContinueOnError]
public sealed class TestTask : FrostingTask
{
public override void Run(BuildContext context)
- {
+ {
context.LoadXaeToPlc(context.TemplateSolutions.FirstOrDefault());
var testRunner = new Cake.Common.Tools.VSTest.VSTestRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
testRunner.Run(context.TemplateTestFiles.Select(p => new FilePath(p)), new Cake.Common.Tools.VSTest.VSTestSettings());
}
}
- [TaskName("TearDown")]
+ [TaskName("Closing" + Const.BuildGroupName)]
[IsDependentOn(typeof(TestTask))]
- public sealed class TearDownTask : FrostingTask
+ [ContinueOnError]
+ public sealed class LastTask : FrostingTask
{
public override void Run(BuildContext context)
{
- context.CloseVsSolution(context.TemplateSolutions.FirstOrDefault());
+
}
}
- [TaskName("Default")]
- [IsDependentOn(typeof(TearDownTask))]
- public class DefaultTask : FrostingTask
+ [TaskName("TearDownTask" + Const.BuildGroupName)]
+ public sealed class TearDownTask : FrostingTaskTeardown
{
-
- }
-}
\ No newline at end of file
+ public override void Teardown(BuildContext context, ITaskTeardownContext info)
+ {
+ context.CloseVsSolution(context.TemplateSolutions.FirstOrDefault());
+ }
+ }
+}
diff --git a/cake/vortex_config.json b/cake/vortex_config.json
new file mode 100644
index 0000000..e6b8525
--- /dev/null
+++ b/cake/vortex_config.json
@@ -0,0 +1,32 @@
+{
+ "ConfigFile": null,
+ "OutputDirectory": "C:\\MTS\\Develop\\gh\\TcOpenGroup\\tcopen-app-templates\\templates\\mts-s-template\\cake\\out",
+ "SolutionPath": "C:\\MTS\\Develop\\gh\\TcOpenGroup\\tcopen-app-templates\\templates\\mts-s-template\\t\\x_template_x.sln",
+ "CompilableAttributesSignatures": [
+ "wpf",
+ "clr"
+ ],
+ "TypeAttributesContainer": {
+ "AttributesDictionary": {
+ "vortex.compiler.Coding.BuilderOnliner": {
+ "Attributes": []
+ },
+ "vortex.compiler.Coding.BuilderPlainer": {
+ "Attributes": []
+ },
+ "vortex.compiler.Coding.BuilderOnlinerInterface": {
+ "Attributes": []
+ },
+ "vortex.compiler.Coding.BuilderShadowerInterface": {
+ "Attributes": []
+ }
+ }
+ },
+ "CreatePlcLibraries": false,
+ "UpdateControllerVersionInfo": false,
+ "CloseVisualStudionOnDone": false,
+ "BuildConnectorProjects": false,
+ "IsLibraryCapable": true,
+ "DoInferUnknownTypes": false,
+ "DoRequireOpenSolution": true
+}
\ No newline at end of file
diff --git a/scaffolder/TcOpen.Scaffold/TcOpen.Scaffold.sln b/scaffolder/TcOpen.Scaffold/TcOpen.Scaffold.sln
index 8aa8a70..feeffb4 100644
--- a/scaffolder/TcOpen.Scaffold/TcOpen.Scaffold.sln
+++ b/scaffolder/TcOpen.Scaffold/TcOpen.Scaffold.sln
@@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.32407.337
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F7A3C700-2833-471F-8976-7B0B33EAB89C}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TcOpen.Scaffold", "src\TcOpen.Scaffold\TcOpen.Scaffold.csproj", "{13093824-9D60-4DCA-8665-43B803BC1FD6}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "tco", "src\TcOpen.Scaffold\tco.csproj", "{13093824-9D60-4DCA-8665-43B803BC1FD6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TcOpen.Scaffold.UI", "src\TcOpen.Scaffold.UI\TcOpen.Scaffold.UI.csproj", "{5AB5EC31-24CA-4CD4-AB1A-E8039D7A29D4}"
EndProject
@@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_repo", "_repo", "{D5417734
..\..\GitVersion.yml = ..\..\GitVersion.yml
EndProjectSection
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TcOpen.Scaffold.Runner", "src\TcOpen.Scaffold.Runner\TcOpen.Scaffold.Runner.csproj", "{7148306E-6608-46D4-9AB4-00B98360FF23}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -30,6 +32,10 @@ Global
{5AB5EC31-24CA-4CD4-AB1A-E8039D7A29D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5AB5EC31-24CA-4CD4-AB1A-E8039D7A29D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5AB5EC31-24CA-4CD4-AB1A-E8039D7A29D4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7148306E-6608-46D4-9AB4-00B98360FF23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7148306E-6608-46D4-9AB4-00B98360FF23}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7148306E-6608-46D4-9AB4-00B98360FF23}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7148306E-6608-46D4-9AB4-00B98360FF23}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -37,6 +43,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{13093824-9D60-4DCA-8665-43B803BC1FD6} = {F7A3C700-2833-471F-8976-7B0B33EAB89C}
{5AB5EC31-24CA-4CD4-AB1A-E8039D7A29D4} = {F7A3C700-2833-471F-8976-7B0B33EAB89C}
+ {7148306E-6608-46D4-9AB4-00B98360FF23} = {F7A3C700-2833-471F-8976-7B0B33EAB89C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {54834823-6D84-4690-AEEF-4FA784731842}
diff --git a/scaffolder/TcOpen.Scaffold/build.ps1 b/scaffolder/TcOpen.Scaffold/build.ps1
deleted file mode 100644
index 90116cd..0000000
--- a/scaffolder/TcOpen.Scaffold/build.ps1
+++ /dev/null
@@ -1,2 +0,0 @@
-dotnet run --project cake/Build.csproj -- $args
-exit $LASTEXITCODE;
\ No newline at end of file
diff --git a/scaffolder/TcOpen.Scaffold/build.sh b/scaffolder/TcOpen.Scaffold/build.sh
deleted file mode 100644
index 1b3d0ee..0000000
--- a/scaffolder/TcOpen.Scaffold/build.sh
+++ /dev/null
@@ -1 +0,0 @@
-dotnet run --project ./cake/Build.csproj -- "$@"
diff --git a/scaffolder/TcOpen.Scaffold/cake/Build.csproj b/scaffolder/TcOpen.Scaffold/cake/Build.csproj
deleted file mode 100644
index cc48703..0000000
--- a/scaffolder/TcOpen.Scaffold/cake/Build.csproj
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- Exe
- net5.0
- $(MSBuildProjectDirectory)
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
-
\ No newline at end of file
diff --git a/scaffolder/TcOpen.Scaffold/cake/Program.cs b/scaffolder/TcOpen.Scaffold/cake/Program.cs
deleted file mode 100644
index 0e57cb5..0000000
--- a/scaffolder/TcOpen.Scaffold/cake/Program.cs
+++ /dev/null
@@ -1,119 +0,0 @@
-using Cake.Core;
-using Cake.Frosting;
-using Cake.Common.Tools.DotNet;
-using System;
-using System.IO;
-using Octokit;
-
-namespace scaffolder_build
-{
- public static class Program
- {
- public static int Main(string[] args)
- {
- return new CakeHost()
- .UseContext()
- .Run(args);
- }
- }
-
- public class BuildContext : FrostingContext
- {
- public bool Delay { get; set; }
-
- public BuildContext(ICakeContext context)
- : base(context)
- {
- Delay = context.Arguments.HasArgument("delay");
- }
-
-
- public void ZipFolder(string sourceFolder, string destinationFile)
- {
- var outputDirectory = new FileInfo(destinationFile).Directory;
-
- if (!outputDirectory.Exists)
- {
- outputDirectory.Create();
- }
-
- System.IO.Compression.ZipFile.CreateFromDirectory(sourceFolder, destinationFile);
- }
- }
-
- [TaskName("Clean")]
- public sealed class CleanTask : FrostingTask
- {
- public override void Run(BuildContext context)
- {
- // delete artifacts folder
- var artifactsFolder = context.FileSystem.GetDirectory("..\\artifacts");
- if (artifactsFolder.Exists)
- {
- artifactsFolder.Delete(true);
- }
-
- context.DotNetClean("..\\TcOpen.Scaffold.sln");
- }
- }
-
- [TaskName("Build")]
- [IsDependentOn(typeof(CleanTask))]
- public sealed class BuildTask : FrostingTask
- {
- // Tasks can be asynchronous
- public override void Run(BuildContext context)
- {
- context.DotNetBuild("..\\TcOpen.Scaffold.sln", new Cake.Common.Tools.DotNet.Build.DotNetBuildSettings()
- {
- Configuration = "Release"
- });
- }
- }
-
- [TaskName("Create artifacts")]
- [IsDependentOn(typeof(BuildTask))]
- public sealed class ArtifactTask : FrostingTask
- {
- public override void Run(BuildContext context)
- {
- context.ZipFolder("..\\src\\TcOpen.Scaffold.UI\\bin\\Release\\net5.0-windows", "..\\artifacts\\TcOpen.Scaffold.UI.zip");
- }
- }
-
-
- [TaskName("Publish release")]
- [IsDependentOn(typeof(ArtifactTask))]
- public sealed class PublishReleaseTask : FrostingTask
- {
- public override void Run(BuildContext context)
- {
- var githubToken = context.Environment.GetEnvironmentVariable("gh-public-repos");
- var githubClient = new GitHubClient(new ProductHeaderValue("TcOpen.Scaffold.UI"));
- githubClient.Credentials = new Credentials(githubToken);
-
- var release = githubClient.Repository.Release.Create(
- "TcOpenGroup",
- "tcopen-app-templates",
- new NewRelease($"v{GitVersionInformation.SemVer}")
- {
- Name = $"v{GitVersionInformation.SemVer}",
- Body = $"Release v{GitVersionInformation.SemVer}",
- Draft = true,
- Prerelease = true
- }
- ).Result;
-
- var asset = new ReleaseAssetUpload("..\\artifacts\\TcOpen.Scaffold.UI.zip", "application/zip", new StreamReader("..\\artifacts\\TcOpen.Scaffold.UI.zip").BaseStream, TimeSpan.FromSeconds(3600));
-
- githubClient.Repository.Release.UploadAsset(release, asset).Wait();
- }
- }
-
-
- [TaskName("Default")]
- [IsDependentOn(typeof(PublishReleaseTask))]
- public class DefaultTask : FrostingTask
- {
- }
-}
\ No newline at end of file
diff --git a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Program.cs b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Program.cs
new file mode 100644
index 0000000..8a90441
--- /dev/null
+++ b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Program.cs
@@ -0,0 +1,29 @@
+using Octokit;
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Net;
+using System.Reflection;
+
+namespace TcOpen.Scaffold
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ var assemblyFile = Path.Combine(Environment.CurrentDirectory, "l\\TcOpen.Scaffold.UI\\TcOpen.Scaffold.UI.exe");
+ string version = "0.0.0";
+ if (File.Exists(assemblyFile))
+ {
+ System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assemblyFile);
+ version = fvi.ProductVersion;
+ }
+
+ Updater.UpdateToNewestRelease(Updater.GetNewestVersion(version));
+
+ Process.Start(assemblyFile);
+ }
+ }
+}
diff --git a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Properties/PublishProfiles/FolderProfile.pubxml b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Properties/PublishProfiles/FolderProfile.pubxml
new file mode 100644
index 0000000..2936717
--- /dev/null
+++ b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Properties/PublishProfiles/FolderProfile.pubxml
@@ -0,0 +1,18 @@
+
+
+
+
+ Release
+ Any CPU
+ C:\MTS\Develop\gh\TcOpenGroup\tcopen-app-templates\scaffolder\TcOpen.Scaffold\src\TcOpen.Scaffold.Runner\Publish
+ FileSystem
+ net5.0
+ true
+ win-x86
+ True
+ True
+ False
+
+
\ No newline at end of file
diff --git a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Properties/launchSettings.json b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Properties/launchSettings.json
new file mode 100644
index 0000000..609cfe5
--- /dev/null
+++ b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Properties/launchSettings.json
@@ -0,0 +1,7 @@
+{
+ "profiles": {
+ "TcOpen.Scaffold.Updater": {
+ "commandName": "Project"
+ }
+ }
+}
\ No newline at end of file
diff --git a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/TcOpen.Scaffold.Runner.csproj b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/TcOpen.Scaffold.Runner.csproj
new file mode 100644
index 0000000..ff39865
--- /dev/null
+++ b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/TcOpen.Scaffold.Runner.csproj
@@ -0,0 +1,18 @@
+
+
+ Exe
+ net5.0
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
diff --git a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Updater.cs b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Updater.cs
new file mode 100644
index 0000000..e759b10
--- /dev/null
+++ b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.Runner/Updater.cs
@@ -0,0 +1,143 @@
+using Octokit;
+using System;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Net;
+using System.Reflection;
+
+namespace TcOpen.Scaffold
+{
+ public class Updater
+ {
+ public static Release GetNewestVersion(string currentVersion)
+ {
+ Console.WriteLine("Checking for latest version...");
+
+ var githubToken = Environment.GetEnvironmentVariable("gh-public-repos");
+ var githubClient = new GitHubClient(new ProductHeaderValue(Guid.NewGuid().ToString()));
+ if (githubToken != null)
+ {
+ githubClient.Credentials = new Credentials(githubToken);
+ }
+
+ var releases = githubClient.Repository.Release.GetAll("TcOpenGroup", "tcopen-app-templates").Result.ToList();
+
+ var versions = releases.Select(p =>
+ {
+ Semver.SemVersion semVersion = null;
+
+ if (!Semver.SemVersion.TryParse(p.Name, Semver.SemVersionStyles.Any, out semVersion))
+ {
+ semVersion = Semver.SemVersion.ParsedFrom(0, 0, 0);
+ }
+
+ return new { Version = semVersion, Release = p };
+ });
+
+ Semver.SemVersion currentSemVersion;
+ Semver.SemVersion.TryParse(currentVersion, Semver.SemVersionStyles.Any, out currentSemVersion);
+
+ var latestVersion = versions.Where(p => p.Version >= currentSemVersion).OrderBy(p => p.Version).LastOrDefault();
+
+ if (latestVersion != null)
+ {
+ Console.WriteLine($"Newer version detected '{latestVersion.Version}'.");
+ }
+ else
+ {
+ Console.WriteLine($"Up to date. Version in use '{currentSemVersion}'.");
+ }
+
+ return latestVersion?.Release;
+ }
+
+ public static void UpdateToNewestRelease(Release release)
+ {
+ if (release == null)
+ {
+ return;
+ }
+
+ Console.WriteLine($"Downloading new version {release.Name}...");
+
+ var assets = release.Assets.Select(p => new { p.Name, p.BrowserDownloadUrl });
+ //// self contained does not have .dll but only exe, entry assembly returns '.dll' file though. In self-contained we need to the the location of exe file.
+ //var entryAssemblyFileInfo = new FileInfo(Assembly.GetEntryAssembly().Location);
+ //var entryAssembly = entryAssemblyFileInfo.Extension == "exe" ? entryAssemblyFileInfo.FullName : entryAssemblyFileInfo.FullName.Replace(".dll", ".exe");
+ //var currentDirectory = new FileInfo(entryAssembly).Directory.FullName;
+ var outputDirectory = Path.Combine(Environment.CurrentDirectory, "l");
+
+ if (!Directory.Exists(outputDirectory))
+ {
+ Directory.CreateDirectory(outputDirectory);
+ }
+ else
+ {
+ Directory.Delete(outputDirectory, true);
+ Directory.CreateDirectory(outputDirectory);
+ }
+
+ foreach (var item in assets)
+ {
+ using (var client = new WebClient())
+ {
+ var outputFileName = new FileInfo(Path.Combine(outputDirectory, item.Name));
+ var fileNameWithoutExtension = outputFileName.FullName.Remove(outputFileName.FullName.Length - outputFileName.Extension.Length, outputFileName.Extension.Length);
+ client.DownloadFile(item.BrowserDownloadUrl, Path.Combine(outputDirectory, outputFileName.FullName));
+ using (var zip = ZipFile.OpenRead(outputFileName.FullName))
+ {
+ zip.ExtractToDirectory(Path.Combine(outputDirectory, fileNameWithoutExtension));
+ }
+ }
+ }
+ }
+
+ private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
+ {
+ DirectoryInfo dir = new DirectoryInfo(sourceDirName);
+ DirectoryInfo[] dirs = dir.GetDirectories();
+
+ // If the source directory does not exist, throw an exception.
+ if (!dir.Exists)
+ {
+ throw new DirectoryNotFoundException(
+ "Source directory does not exist or could not be found: "
+ + sourceDirName);
+ }
+
+ // If the destination directory does not exist, create it.
+ if (!Directory.Exists(destDirName))
+ {
+ Directory.CreateDirectory(destDirName);
+ }
+
+
+ // Get the file contents of the directory to copy.
+ FileInfo[] files = dir.GetFiles();
+
+ foreach (FileInfo file in files)
+ {
+ // Create the path to the new copy of the file.
+ string temppath = Path.Combine(destDirName, file.Name);
+
+ // Copy the file.
+ file.CopyTo(temppath, true);
+ }
+
+ // If copySubDirs is true, copy the subdirectories.
+ if (copySubDirs)
+ {
+
+ foreach (DirectoryInfo subdir in dirs)
+ {
+ // Create the subdirectory.
+ string temppath = Path.Combine(destDirName, subdir.Name);
+
+ // Copy the subdirectories.
+ DirectoryCopy(subdir.FullName, temppath, copySubDirs);
+ }
+ }
+ }
+ }
+}
diff --git a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/MainWindow.xaml b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/MainWindow.xaml
index 6abfcc7..8d6290f 100644
--- a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/MainWindow.xaml
+++ b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/MainWindow.xaml
@@ -14,6 +14,7 @@
+
@@ -47,5 +48,6 @@
+
diff --git a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/MainWindowViewModel.cs b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/MainWindowViewModel.cs
index 21e37c2..7656615 100644
--- a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/MainWindowViewModel.cs
+++ b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/MainWindowViewModel.cs
@@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Windows;
using System.Windows.Forms;
namespace TcOpen.Scaffold.UI
@@ -13,17 +14,24 @@ public class MainWindowViewModel : Prism.Mvvm.BindableBase
public MainWindowViewModel()
{
+ // Checking for updates
ScaffoldCommand = new Prism.Commands.DelegateCommand(() => Exectute());
SelectOutputFolderCommand = new Prism.Commands.DelegateCommand(() => SelectOutputFolder());
IsNotScaffoling = true;
}
+ public string Version
+ {
+ get
+ {
+ return GitVersionInformation.SemVer;
+ }
+ }
public bool IsNotScaffoling
{
get => isScaffoling;
set { isScaffoling = value; this.RaisePropertyChanged(nameof(IsNotScaffoling)); }
}
-
private async void Exectute()
{
IsNotScaffoling = false;
@@ -31,7 +39,6 @@ private async void Exectute()
await Task.Run(() => context.Execute());
IsNotScaffoling = true;
}
-
private void SelectOutputFolder()
{
using (var fbd = new FolderBrowserDialog())
@@ -44,9 +51,7 @@ private void SelectOutputFolder()
}
}
}
-
public Options Options { get; set; } = new Options() { Branch = "dev", ProjectName = "MyProject", TemplateName = "mts-s-template" };
-
public Prism.Commands.DelegateCommand ScaffoldCommand { get; }
public Prism.Commands.DelegateCommand SelectOutputFolderCommand { get; }
}
diff --git a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/TcOpen.Scaffold.UI.csproj b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/TcOpen.Scaffold.UI.csproj
index 2195ea4..bee7f5c 100644
--- a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/TcOpen.Scaffold.UI.csproj
+++ b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold.UI/TcOpen.Scaffold.UI.csproj
@@ -3,6 +3,8 @@
WinExe
net5.0-windows
+ false
+ win-x64
true
true
@@ -12,13 +14,13 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
-
+
+
diff --git a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold/Context.cs b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold/Context.cs
index 835b1ca..eb79192 100644
--- a/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold/Context.cs
+++ b/scaffolder/TcOpen.Scaffold/src/TcOpen.Scaffold/Context.cs
@@ -1,10 +1,13 @@
-using System;
+using Octokit;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http.Headers;
+using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
@@ -36,10 +39,9 @@ public Context(Options options)
CurrentDirectory = Environment.CurrentDirectory;
}
}
-
+
public void Execute()
- {
- var branches = GetGitHubRepositoryBranches();
+ {
DownloadBranchAndExtractBranch();
CopyTemplateFolder();
ReplaceTemplateTags();
@@ -175,20 +177,6 @@ private static void DirectoryCopy(
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
- }
-
- private IEnumerable