Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-Type -AssemblyName System.Windows.Forms
- Add-Type -AssemblyName System.Drawing
- # Create OpenFileDialog object
- $dialog = New-Object System.Windows.Forms.OpenFileDialog
- $dialog.Filter = "Solution Files (*.sln)|*.sln"
- $dialog.InitialDirectory = [Environment]::GetFolderPath("Desktop")
- # Show the dialog and check if the user selected a file
- if ($dialog.ShowDialog() -eq 'OK') {
- $global:buildConfig = ""
- $global:platformTarget = ""
- $global:buildName = ""
- $global:outputDir = ""
- # Get the selected file path
- $slnName = $dialog.FileName
- #$slnPath = [System.IO.Path]::GetDirectoryName($dialog.FileName)
- #$slnfullPath = [System.IO.Path]::GetFullPath([System.IO.Path]::GetDirectoryName($dialog.FileName))
- # Create the output directory path
- $global:outputDir = Join-Path (Split-Path $slnName) "thunder"
- # Create the output directory if it doesn't exist
- if (!(Test-Path $global:outputDir)) {
- New-Item -ItemType Directory -Path $global:outputDir | Out-Null
- }
- # Choose the target platform
- $platformDialog = New-Object System.Windows.Forms.Form
- $platformDialog.AutoSize = $true
- $platformDialog.Text = "Choose Target Platform"
- $releaseRadioButton = New-Object System.Windows.Forms.RadioButton
- $releaseRadioButton.Location = New-Object System.Drawing.Point(20, 20)
- $releaseRadioButton.Text = "Release"
- $releaseRadioButton.Checked = $true
- $debugRadioButton = New-Object System.Windows.Forms.RadioButton
- $debugRadioButton.Location = New-Object System.Drawing.Point(20, 40)
- $debugRadioButton.Text = "Debug"
- $x86Button = New-Object System.Windows.Forms.RadioButton
- $x86Button.Location = New-Object System.Drawing.Point(20, 20)
- $x86Button.Text = "x86"
- $x64Button = New-Object System.Windows.Forms.RadioButton
- $x64Button.Location = New-Object System.Drawing.Point(20, 40)
- $x64Button.Text = "x64"
- $anyCpuButton = New-Object System.Windows.Forms.RadioButton
- $anyCpuButton.Location = New-Object System.Drawing.Point(20, 60)
- $anyCpuButton.Text = "AnyCPU"
- $okButton = New-Object System.Windows.Forms.Button
- $okButton.Location = New-Object System.Drawing.Point(20, 80)
- $okButton.Text = "OK"
- $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
- $platformDialog = New-Object System.Windows.Forms.Form
- $platformDialog.ClientSize = New-Object System.Drawing.Size(200, 150)
- $platformDialog.Text = "Select Platform"
- $platformDialog.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
- $platformDialog.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
- $platformDialog.Controls.Add($x86Button)
- $platformDialog.Controls.Add($x64Button)
- $platformDialog.Controls.Add($anyCpuButton)
- $platformDialog.Controls.Add($okButton)
- #$platformDialog.Controls.AddRange(@($x86Button, $x64Button, $anyCpuButton, $okButton))
- $result = $platformDialog.ShowDialog()
- # Prompt the user for a build name
- $buildNameDialog = New-Object System.Windows.Forms.Form
- $buildNameDialog.Text = "Build Name"
- $buildNameDialog.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
- $buildNameDialog.MaximizeBox = $false
- $buildNameDialog.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
- $buildNameLabel = New-Object System.Windows.Forms.Label
- $buildNameLabel.Location = New-Object System.Drawing.Point(10, 20)
- $buildNameLabel.Size = New-Object System.Drawing.Size(200, 20)
- $buildNameLabel.Text = "Enter a name for this build:"
- $buildNameTextBox = New-Object System.Windows.Forms.TextBox
- $buildNameTextBox.Location = New-Object System.Drawing.Point(10, 40)
- $buildNameTextBox.Size = New-Object System.Drawing.Size(200, 20)
- $buildNameTextBox.Add_KeyPress({
- if ($_.KeyChar -eq [char]::Enter) {
- $global:buildName = $buildNameTextBox.Text
- $buildNameDialog.DialogResult = [System.Windows.Forms.DialogResult]::OK
- $buildNameDialog.Close()
- }
- })
- $okButton = New-Object System.Windows.Forms.Button
- $okButton.Location = New-Object System.Drawing.Point(70, 70)
- $okButton.Size = New-Object System.Drawing.Size(75, 23)
- $okButton.Text = "OK"
- $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
- $buildNameDialog.Controls.Add($buildNameLabel)
- $buildNameDialog.Controls.Add($buildNameTextBox)
- $buildNameDialog.Controls.Add($okButton)
- $buildNameDialogResult = $buildNameDialog.ShowDialog()
- if ($buildNameDialogResult -eq [System.Windows.Forms.DialogResult]::OK) {
- $global:buildName = $buildNameTextBox.Text
- }
- # Prompt the user for the build configuration
- $buildConfigDialog = New-Object System.Windows.Forms.Form
- $buildConfigDialog.Text = "Build Configuration"
- $buildConfigDialog.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
- $buildConfigDialog.MaximizeBox = $false
- $buildConfigDialog.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
- $releaseRadioButton = New-Object System.Windows.Forms.RadioButton
- $releaseRadioButton.Location = New-Object System.Drawing.Point(20, 20)
- $releaseRadioButton.Text = "Release"
- $releaseRadioButton.Checked = $true
- $debugRadioButton = New-Object System.Windows.Forms.RadioButton
- $debugRadioButton.Location = New-Object System.Drawing.Point(20, 40)
- $debugRadioButton.Text = "Debug"
- $buildConfigDialog.Controls.Add($releaseRadioButton)
- $buildConfigDialog.Controls.Add($debugRadioButton)
- $buildConfigDialog.Controls.Add($okButton)
- #Copy the configuration file to the output directory
- $configFileName = [System.IO.Path]::GetFileNameWithoutExtension($slnName) + ".config"
- $configFilePath = Join-Path $slnName $configFileName
- if (Test-Path $configFilePath) {
- Copy-Item -Path $configFilePath -Destination $global:outputDir -Force
- }
- $buildConfigDialogResult = $buildConfigDialog.ShowDialog()
- if ($buildConfigDialogResult -eq [System.Windows.Forms.DialogResult]::OK) {
- $global:buildConfig = ""
- if ($releaseRadioButton.Checked) {
- $global:buildConfig = "Release"
- } elseif ($debugRadioButton.Checked) {
- $global:buildConfig = "Debug"
- }
- # Modify the project file to include PostBuildEvent
- $slnPath = Split-Path $slnName
- $projectFiles = Get-ChildItem -Path $slnPath -Filter "*.csproj"
- foreach ($projectFile in $projectFiles) {
- $projectXml = [xml](Get-Content $projectFile.FullName)
- switch ($result) {
- "x86" {
- $projectXml.Project.PropertyGroup.PlatformTarget = "x86"
- break
- }
- "x64" {
- $projectXml.Project.PropertyGroup.PlatformTarget = "x64"
- break
- }
- "AnyCPU" {
- $projectXml.Project.PropertyGroup.PlatformTarget = "AnyCPU"
- break
- }
- }
- $postBuildNode = $projectXml.Project.PropertyGroup.PostBuildEvent
- if (!$postBuildNode) {
- $postBuildNode = $projectXml.CreateElement("PostBuildEvent")
- $postBuildNode.InnerText = 'if "$(PlatformTarget)" == "x64" ( call "$(VCInstallDir)Auxiliary\Build\vcvars64.bat" ) else ( call "$(VCInstallDir)Auxiliary\Build\vcvars32.bat" ) editbin /largeaddressaware /TSAWARE "$(TargetPath)" sn -R "$(TargetPath)" "$(ProjectDir)\$(TargetFileName)"'
- $projectXml.Project.PropertyGroup.AppendChild($postBuildNode) | Out-Null
- }
- $projectXml.Save($projectFile.FullName)
- }
- # Compile the solution using MSBuild
- #$msbuildPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"
- $msbuildPath = "H:\Microsoft\Microsoft Visual Studio\Msbuild\Current\Bin\MSBuild.exe" #2022
- $global:platformTarget = ""
- if ($x86Button.Checked) {
- $global:platformTarget = "x86"
- } elseif ($x64Button.Checked) {
- $global:platformTarget = "x64"
- } elseif ($anyCpuButton.Checked) {
- $global:platformTarget = "AnyCpu"
- }
- & $msbuildPath "$slnName" /t:Rebuild /p:Configuration=$global:buildConfig /p:Platform=$global:platformTarget /p:OutputPath="$global:outputDir" /p:BuildName="$global:buildName"
- pause
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement