Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Template system update
Serialization update for templating to match latest PSFramework version and remove dependency from typeconverter in general
  • Loading branch information
FriedrichWeinmann committed Oct 4, 2024
commit 1e85b98135f3fdc82bfa423334cac4a2d8113c54
4 changes: 2 additions & 2 deletions PSModuleDevelopment/PSModuleDevelopment.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Version number of this module.

ModuleVersion = '2.2.11.168'
ModuleVersion = '2.2.12.171'

# ID used to uniquely identify this module
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'
Expand All @@ -28,7 +28,7 @@
# Modules that must be imported into the global environment prior to importing
# this module
RequiredModules = @(
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.7.270' }
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.12.346' }
@{ ModuleName = 'string'; ModuleVersion = '1.1.3' }
)

Expand Down
Binary file modified PSModuleDevelopment/bin/PSModuleDevelopment.dll
Binary file not shown.
Binary file modified PSModuleDevelopment/bin/PSModuleDevelopment.pdb
Binary file not shown.
46 changes: 46 additions & 0 deletions PSModuleDevelopment/bin/PSModuleDevelopment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions PSModuleDevelopment/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.2.12.171 (2024-10-04)

+ Upd: Raised PSFramework dependency due to critical security update
+ Fix: Invoke-PSMDTemplate - fails on non-Windows
+ Fix: Invoke-PSMDTemplate - fails with latest PSFramework version

## 2.2.11.168 (2024-05-31)

+ Upd: Template AzureFunction - added config option to override http Endpoint methods (#198)
Expand Down
4 changes: 2 additions & 2 deletions PSModuleDevelopment/functions/templating/New-PSMDTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@

$template.CreatedOn = (Get-Date).Date

$template | Export-Clixml -Path (Join-Path $exportFolder $fileName)
$template.ToTemplateInfo() | Export-Clixml -Path (Join-Path $exportFolder $infoFileName)
$template | Export-PSFClixml -Path (Join-Path $exportFolder $fileName) -Depth 99
$template.ToTemplateInfo() | Export-PSFClixml -Path (Join-Path $exportFolder $infoFileName)
}
}
38 changes: 38 additions & 0 deletions build/vsts-build-library.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<#
.SYNOPSIS
Builds the PSFramework binary library from source.

.DESCRIPTION
Builds the PSFramework binary library from source.

.PARAMETER WorkingDirectory
Path where the project root is.
Defaults to the parent folder this file is in.

.EXAMPLE
PS C:\> .\vsts-build-library.ps1

Builds the PSFramework binary library from source.
#>
[CmdletBinding()]
param (
$WorkingDirectory
)

#region Handle Working Directory Defaults
if (-not $WorkingDirectory)
{
if ($env:RELEASE_PRIMARYARTIFACTSOURCEALIAS)
{
$WorkingDirectory = Join-Path -Path $env:SYSTEM_DEFAULTWORKINGDIRECTORY -ChildPath $env:RELEASE_PRIMARYARTIFACTSOURCEALIAS
}
else { $WorkingDirectory = $env:SYSTEM_DEFAULTWORKINGDIRECTORY }
}
if (-not $WorkingDirectory) { $WorkingDirectory = Split-Path $PSScriptRoot }
#endregion Handle Working Directory Defaults

# Build Library
dotnet build "$WorkingDirectory\library\PSModuleDevelopment\PSModuleDevelopment.sln"
if ($LASTEXITCODE -ne 0) {
throw "Failed to build PSModuleDevelopment.dll!"
}
26 changes: 24 additions & 2 deletions dev/launch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ param (
[switch]
$Local,

[switch]
$Build,

[ValidateSet('Desktop', 'Core')]
[string]
$PSVersion
Expand All @@ -16,7 +19,10 @@ if (-not $Local) {
if ($PSVersion -eq 'Desktop') { $application = 'powershell.exe'}
}

Start-Process $application -ArgumentList @('-NoExit', '-NoProfile', '-File', "$PSScriptRoot\launch.ps1", '-Local')
$arguments = @('-NoExit', '-NoProfile', '-File', "$PSScriptRoot\launch.ps1", '-Local')
if ($Build) { $arguments += '-Build' }

Start-Process $application -ArgumentList $arguments
return
}
#endregion Launch in new cponsole
Expand Down Expand Up @@ -80,10 +86,26 @@ function Import-PsmdModule {
# Does not work during initial start
# [Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory("ipmo '$ProjectPath\PSModuleDevelopment\PSModuleDevelopment.psd1'")
}

function Build-PsmdModule {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$ProjectPath
)

Write-Host "Building Library. This may require the .NET 4.8 Targeting Pack"
try { $null = & "$ProjectPath\build\vsts-build-library.ps1" }
catch {
Write-Host "Targeting pack Download Link: https://dotnet.microsoft.com/en-us/download/visual-studio-sdks?cid=getdotnetsdk"
throw
}
}
#endregion Functions

$projectRoot = Resolve-Path -Path "$PSScriptRoot\.."
$templateRoot = New-TemporaryPath -Prefix PsmdTemplate
#Build-PsmdModule -ProjectPath $projectRoot
if ($Build) { Build-PsmdModule -ProjectPath $projectRoot }
Import-PsmdModule -ProjectPath $projectRoot
Build-Template -RootPath $templateRoot -ProjectPath $projectRoot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"RootPath":"F:\\Code\\Github\\PSModuleDevelopment\\library\\PSModuleDevelopment\\PSModuleDevelopment","ProjectFileName":"PSModuleDevelopment.csproj","Configuration":"Debug|AnyCPU","FrameworkPath":"","Sources":[{"SourceFile":"Format\\Column.cs"},{"SourceFile":"Format\\Alignment.cs"},{"SourceFile":"Format\\ColumnTransformation.cs"},{"SourceFile":"Format\\Document.cs"},{"SourceFile":"Format\\TableDefinition.cs"},{"SourceFile":"Format\\ViewDefinitionBase.cs"},{"SourceFile":"Properties\\AssemblyInfo.cs"},{"SourceFile":"PsmdAssembly\\Constructor.cs"},{"SourceFile":"Template\\Parameter\\ParameterBase.cs"},{"SourceFile":"Template\\ParameterScript.cs"},{"SourceFile":"Template\\Parameter\\ParameterPrompt.cs"},{"SourceFile":"Template\\Parameter\\ParameterScript.cs"},{"SourceFile":"Template\\Parameter\\ScriptExecutionTime.cs"},{"SourceFile":"Template\\Store.cs"},{"SourceFile":"Template\\Template.cs"},{"SourceFile":"Template\\TemplateInfo.cs"},{"SourceFile":"Template\\TemplateItemBase.cs"},{"SourceFile":"Template\\TemplateItemFile.cs"},{"SourceFile":"Template\\TemplateItemFolder.cs"},{"SourceFile":"Template\\TemplateResult.cs"},{"SourceFile":"Template\\TemplateType.cs"},{"SourceFile":"Utility\\LinesOfCode.cs"},{"SourceFile":"Utility\\PropertySearchResult.cs"},{"SourceFile":"Utility\\TextAlignment.cs"},{"SourceFile":"Utility\\TextHeader.cs"},{"SourceFile":"Utility\\UtilityHost.cs"},{"SourceFile":"obj\\Debug\\.NETFramework,Version=v4.8.AssemblyAttributes.cs"}],"References":[{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\Microsoft.CSharp.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\mscorlib.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"F:\\Code\\Github\\psframework\\PSFramework\\bin\\PSFramework.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Core.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Data.DataSetExtensions.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Data.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Windows\\Microsoft.NET\\assembly\\GAC_MSIL\\System.Management.Automation\\v4.0_3.0.0.0__31bf3856ad364e35\\System.Management.Automation.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Net.Http.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Xml.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""},{"Reference":"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8\\System.Xml.Linq.dll","ResolvedFrom":"","OriginalItemSpec":"","Name":"","EmbedInteropTypes":false,"CopyLocal":false,"IsProjectReference":false,"ProjectPath":""}],"Analyzers":[],"Outputs":[{"OutputItemFullPath":"F:\\Code\\Github\\PSModuleDevelopment\\PSModuleDevelopment\\bin\\PSModuleDevelopment.dll","OutputItemRelativePath":"PSModuleDevelopment.dll"},{"OutputItemFullPath":"","OutputItemRelativePath":""}],"CopyToOutputEntries":[]}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Compile Include="Template\Parameter\ScriptExecutionTime.cs" />
<Compile Include="Template\Store.cs" />
<Compile Include="Template\Template.cs" />
<Compile Include="Template\TemplateHost.cs" />
<Compile Include="Template\TemplateInfo.cs" />
<Compile Include="Template\TemplateItemBase.cs" />
<Compile Include="Template\TemplateItemFile.cs" />
Expand All @@ -74,6 +75,7 @@
<Compile Include="Template\TemplateType.cs" />
<Compile Include="Utility\LinesOfCode.cs" />
<Compile Include="Utility\PropertySearchResult.cs" />
<Compile Include="Utility\PSObjectExtension.cs" />
<Compile Include="Utility\TextAlignment.cs" />
<Compile Include="Utility\TextHeader.cs" />
<Compile Include="Utility\UtilityHost.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,15 @@ public ParameterScript(string Name, ScriptBlock ScriptBlock)
this.Name = Name;
this.ScriptBlock = ScriptBlock;
}

/// <summary>
/// Creates a prefilled parameter script. Usually used in fixing serialization the hard way.
/// </summary>
/// <param name="Item">The deserialized ParameterScript item</param>
public ParameterScript(PSObject Item)
{
Name = (string)Item.Properties["Name"].Value;
ScriptBlock = ScriptBlock.Create((string)Item.Properties["ScriptBlock"].Value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using System.Threading.Tasks;
using PSModuleDevelopment.Utility;

namespace PSModuleDevelopment.Template
{
Expand Down Expand Up @@ -96,5 +98,46 @@ public TemplateInfo ToTemplateInfo()

return info;
}

/// <summary>
/// Create a blank template object
/// </summary>
public Template()
{

}

/// <summary>
/// Create a template object based on a deserialized template object
/// </summary>
/// <param name="Item">The deserialized tample object to restore</param>
/// <exception cref="ArgumentException">If anything at all is not as it should be.</exception>
public Template(PSObject Item)
{
try
{
Name = Item.GetValue<string>("Name");
Type = (TemplateType)Item.GetValue<int>("Type");
Version = Item.GetValue<Version>("Version");
Description = Item.GetValue<string>("Description");
Author = Item.GetValue<string>("Author");
CreatedOn = Item.GetValue<DateTime>("CreatedOn");
foreach (object item in Item.GetValue<ArrayList>("Tags"))
Tags.Add((string)item);
foreach (object item in Item.GetValue<ArrayList>("Parameters"))
Parameters.Add((string)item);
foreach (KeyValuePair<string, ParameterScript> entry in Item.GetDictionary<ParameterScript>("Scripts"))
Scripts[entry.Key] =entry.Value;
// Parameters2 not used
foreach (object item in Item.GetValue<ArrayList>("Children"))
Children.Add(TemplateHost.GetTemplateItem(item));

Generation = Item.GetValue<int>("Generation");
}
catch (Exception e)
{
throw new ArgumentException($"Cannot convert {Item} of type {Item.BaseObject.GetType().FullName} to type PSModuleDevelopment.Template.Template! {e.Message}", e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using System.Threading.Tasks;
using PSModuleDevelopment.Utility;

namespace PSModuleDevelopment.Template
{
/// <summary>
/// Static helpers for the template system
/// </summary>
internal static class TemplateHost
{
internal static TemplateItemBase GetTemplateItem(object Item)
{
if (Item.GetType() == typeof(TemplateItemFile))
return (TemplateItemFile)Item;

TemplateItemFolder result = new TemplateItemFolder(); ;
PSObject PSItem = PSObject.AsPSObject(Item);

foreach (object child in PSItem.GetValue<ArrayList>("Children"))
result.Children.Add(GetTemplateItem(child));

result.Name = PSItem.GetValue<string>("Name");
result.RelativePath = PSItem.GetValue<string>("RelativePath");
result.Identifier = PSItem.GetValue<string>("Identifier");
foreach (string entry in PSItem.GetValue<ArrayList>("FileSystemParameterFlat"))
result.FileSystemParameterFlat.Add(entry);
foreach (string entry in PSItem.GetValue<ArrayList>("FileSystemParameterScript"))
result.FileSystemParameterScript.Add(entry);

return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using System.Threading.Tasks;

namespace PSModuleDevelopment.Utility
{
/// <summary>
/// Extends the PSObject with C# convenience
/// </summary>
public static class PSObjectExtension
{
/// <summary>
/// Get the value!
/// </summary>
/// <typeparam name="T">The type of the value</typeparam>
/// <param name="PSObject">The object to extend</param>
/// <param name="Name">The name of the property that has the value</param>
/// <returns>The value</returns>
public static T GetValue<T>(this PSObject PSObject, string Name)
{
PSObject value = PSObject.AsPSObject(PSObject.Properties[Name].Value);
return (T)value.BaseObject;
}

/// <summary>
/// Get a hashtable value!
/// </summary>
/// <typeparam name="T">The type of the values in hashtable</typeparam>
/// <param name="PSObject">The object to extend</param>
/// <param name="Name">The name of the property that has the hashtable</param>
/// <returns>The hashtable!</returns>
public static Dictionary<string, T> GetDictionary<T>(this PSObject PSObject, string Name)
{
Hashtable temp = PSObject.GetValue<Hashtable>(Name);
Dictionary<string, T> result = new Dictionary<string, T>();
foreach (DictionaryEntry pair in temp)
result[(string)pair.Key] = (T)pair.Value;

return result;
}
}
}