mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
PS AddType - Add the ability to supply custom compile symbols for C# code (#54582)
This commit is contained in:
parent
bce75824b1
commit
2750f39391
2 changed files with 31 additions and 2 deletions
|
@ -33,6 +33,11 @@ Function Add-CSharpType {
|
||||||
[Switch] Whether to include debug information in the compiled
|
[Switch] Whether to include debug information in the compiled
|
||||||
assembly. Cannot be used when AnsibleModule is set. This is a no-op
|
assembly. Cannot be used when AnsibleModule is set. This is a no-op
|
||||||
when running on PSCore.
|
when running on PSCore.
|
||||||
|
|
||||||
|
.PARAMETER CompileSymbols
|
||||||
|
[String[]] A list of symbols to be defined during compile time. These are
|
||||||
|
added to the existing symbols, 'CORECLR', 'WINDOWS', 'UNIX' that are set
|
||||||
|
conditionalls in this cmdlet.
|
||||||
#>
|
#>
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)][AllowEmptyCollection()][String[]]$References,
|
[Parameter(Mandatory=$true)][AllowEmptyCollection()][String[]]$References,
|
||||||
|
@ -40,7 +45,8 @@ Function Add-CSharpType {
|
||||||
[Switch]$PassThru,
|
[Switch]$PassThru,
|
||||||
[Parameter(Mandatory=$true, ParameterSetName="Module")][Object]$AnsibleModule,
|
[Parameter(Mandatory=$true, ParameterSetName="Module")][Object]$AnsibleModule,
|
||||||
[Parameter(ParameterSetName="Manual")][String]$TempPath = $env:TMP,
|
[Parameter(ParameterSetName="Manual")][String]$TempPath = $env:TMP,
|
||||||
[Parameter(ParameterSetName="Manual")][Switch]$IncludeDebugInfo
|
[Parameter(ParameterSetName="Manual")][Switch]$IncludeDebugInfo,
|
||||||
|
[String[]]$CompileSymbols = @()
|
||||||
)
|
)
|
||||||
if ($null -eq $References -or $References.Length -eq 0) {
|
if ($null -eq $References -or $References.Length -eq 0) {
|
||||||
return
|
return
|
||||||
|
@ -49,7 +55,7 @@ Function Add-CSharpType {
|
||||||
# define special symbols CORECLR, WINDOWS, UNIX if required
|
# define special symbols CORECLR, WINDOWS, UNIX if required
|
||||||
# the Is* variables are defined on PSCore, if absent we assume an
|
# the Is* variables are defined on PSCore, if absent we assume an
|
||||||
# older version of PowerShell under .NET Framework and Windows
|
# older version of PowerShell under .NET Framework and Windows
|
||||||
$defined_symbols = [System.Collections.ArrayList]@()
|
$defined_symbols = [System.Collections.ArrayList]$CompileSymbols
|
||||||
$is_coreclr = Get-Variable -Name IsCoreCLR -ErrorAction SilentlyContinue
|
$is_coreclr = Get-Variable -Name IsCoreCLR -ErrorAction SilentlyContinue
|
||||||
if ($null -ne $is_coreclr) {
|
if ($null -ne $is_coreclr) {
|
||||||
if ($is_coreclr.Value) {
|
if ($is_coreclr.Value) {
|
||||||
|
|
|
@ -204,5 +204,28 @@ Add-CSharpType -References $ignored_warning
|
||||||
$actual = [Namespace7.Class7]::GetString()
|
$actual = [Namespace7.Class7]::GetString()
|
||||||
Assert-Equals -actual $actual -expected "abc"
|
Assert-Equals -actual $actual -expected "abc"
|
||||||
|
|
||||||
|
$defined_symbol = @'
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Namespace8
|
||||||
|
{
|
||||||
|
public class Class8
|
||||||
|
{
|
||||||
|
public static string GetString()
|
||||||
|
{
|
||||||
|
#if SYMBOL1
|
||||||
|
string a = "symbol";
|
||||||
|
#else
|
||||||
|
string a = "no symbol";
|
||||||
|
#endif
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'@
|
||||||
|
Add-CSharpType -References $defined_symbol -CompileSymbols "SYMBOL1"
|
||||||
|
$actual = [Namespace8.Class8]::GetString()
|
||||||
|
Assert-Equals -actual $actual -expected "symbol"
|
||||||
|
|
||||||
$result.res = "success"
|
$result.res = "success"
|
||||||
Exit-Json -obj $result
|
Exit-Json -obj $result
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue