Created
April 19, 2019 19:04
-
-
Save atrenton/6a8658036f2baaf6b4e38609c07fb03d to your computer and use it in GitHub Desktop.
PowerShell script: Use dotnet CLI to create a Windows 32-bit C# class library solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dotnet-Create-Win32-Classlib-Solution.ps1 | |
# Uses dotnet CLI to create a Windows 32-bit C# class library solution | |
function not-exist { -not (Test-Path $args) } | |
Set-Alias !exist not-exist -Option "Constant, AllScope" | |
Set-Alias exist Test-Path -Option "Constant, AllScope" | |
# TODO: Configure | |
$classlib = '32-bit' # project subdirectory (I.E. ~\src\32-bit) | |
$repoName = 'Windows.Classlib' # C# project namespace | |
$repoPath = 'D:\Repos\username' # your project repository root directory | |
$repository = Join-Path -Path $repoPath -ChildPath $repoName | |
$sln = $repoName + '.sln' | |
$srcDir = 'src' | |
if (not-exist $repository) { mkdir $repository > $null } | |
Set-Location $repository | |
if (not-exist $srcDir) { mkdir $srcDir > $null } | |
Set-Location $srcDir | |
if (not-exist $sln) { dotnet new sln -n $repoName } | |
if (not-exist $classlib) { | |
dotnet new classlib --no-restore ` | |
--target-framework-override net462 ` | |
-n $repoName ` | |
-o $classlib | |
} | |
$csproj = Join-Path -Path $classlib -ChildPath $($repoName + '.csproj') -Resolve | |
# Append <Platforms>x86</Platforms> to .csproj to select 32-bit architecture | |
$xmlDoc = New-Object System.Xml.XmlDocument | |
$xmlDoc.Load($csproj) | |
$platforms = $xmlDoc.CreateElement('Platforms') | |
$null = $platforms.AppendChild($xmlDoc.CreateTextNode('x86')) | |
$null = $xmlDoc.Project.PropertyGroup.AppendChild($platforms) | |
$xmlSettings = New-Object System.Xml.XmlWriterSettings | |
$xmlSettings.Indent = $true | |
$xmlSettings.OmitXmlDeclaration = $true | |
$xmlWriter = [System.Xml.XmlWriter]::Create($csproj, $xmlSettings) | |
$xmlDoc.Save($xmlWriter) | |
$xmlWriter.Close() | |
# Configure postSolution section in .sln file for x86 project | |
dotnet sln $sln add $csproj | |
# Build solution | |
dotnet build $sln |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment