Visual Studio 2022-制作WindowStargetPlatFormversion(SDK)非全球?

问题描述 投票:0回答:0
<WindowsTargetPlatformVersion>

定义为

global
,这意味着如果我更改它,它将为所有人更改。
我可以添加属性表并手动添加
<WindowsTargetPlatformVersion>
,但是您不能在需要时使用UI更改它。
基本上,问题是,我如何制作

<WindowsTargetPlatformVersion>

非全球,以便我可以使用IDE独立为每个平台设置它? tia !!

    

与chatgpt一起工作,“我们”提出了这个powershell脚本,可以将其从全局部分移至其他部分。 在尝试使用之前,请确保您备份。 一旦在其上运行脚本,您就可以像平台工具集一样管理SDK。

param(
    [Parameter(Mandatory=$true)]
    [string]$vcxprojPath
)

# Load the .vcxproj file as XML
[xml]$xml = Get-Content $vcxprojPath

# Define a namespace manager (if needed)
$namespaceManager = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$namespaceManager.AddNamespace("ns", $xml.DocumentElement.NamespaceURI)

# Find the global PropertyGroup with Label="Globals"
$globalGroup = $xml.SelectSingleNode("//ns:PropertyGroup[@Label='Globals']", $namespaceManager)

if ($globalGroup -ne $null) {
    Write-Host "Found Global PropertyGroup with Label='Globals'"

    # Search for WindowsTargetPlatformVersion
    $globalSdkNode = $globalGroup.SelectSingleNode("ns:WindowsTargetPlatformVersion", $namespaceManager)

    if ($globalSdkNode -ne $null) {
        $sdkVersion = $globalSdkNode.InnerText
        Write-Host "Found Global SDK Version: $sdkVersion"

        # Remove it from the global PropertyGroup
        $globalGroup.RemoveChild($globalSdkNode) | Out-Null
        Write-Host "Removed WindowsTargetPlatformVersion from Globals section."

        # Add it to all PropertyGroups that contain PlatformToolset
        $xml.SelectNodes("//ns:PropertyGroup[ns:PlatformToolset]", $namespaceManager) | ForEach-Object {
            if ($_.SelectSingleNode("ns:WindowsTargetPlatformVersion", $namespaceManager) -eq $null) {
                $newNode = $xml.CreateElement("WindowsTargetPlatformVersion", $xml.DocumentElement.NamespaceURI)
                $newNode.InnerText = $sdkVersion
                $_.AppendChild($newNode) | Out-Null
                Write-Host "Added SDK version ($sdkVersion) to PropertyGroup with PlatformToolset: $($_.PlatformToolset)"
            }
        }

        # Generate a temp file with a timestamp (YYYYMMDD_HHMMSS_MS.tmp)
        $timestamp = Get-Date -Format "yyyyMMdd_HHmmss_fff"
        $tempFilePath = [System.IO.Path]::Combine((Get-Item $vcxprojPath).DirectoryName, "temp_$timestamp.tmp")

        # Save changes to the temp file
        $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
        $xmlWriterSettings = New-Object System.Xml.XmlWriterSettings
        $xmlWriterSettings.Indent = $true
        $xmlWriterSettings.Encoding = $utf8NoBom
        $xmlWriter = [System.Xml.XmlWriter]::Create($tempFilePath, $xmlWriterSettings)
        $xml.Save($xmlWriter)
        $xmlWriter.Close()

        # Replace the original file with the modified temp file
        Move-Item -Path $tempFilePath -Destination $vcxprojPath -Force

        Write-Host "Updated $vcxprojPath successfully!"
    } else {
        Write-Host "WindowsTargetPlatformVersion NOT FOUND in 'Globals' section."
    }
} else {
    Write-Host "No PropertyGroup with Label='Globals' found."
}

visual-studio visual-studio-2022 project-properties
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.