admin管理员组文章数量:1312686
I need to have a different SDK based on the platform (Win32/x64/ARM64/etc..). Currently the .vcxproj
defines <WindowsTargetPlatformVersion>
as global
which means if I change it for one, it changes for all.
I can add a property sheet and manually add <WindowsTargetPlatformVersion>
but you can't use the UI to change it when needed.
So basically the question is, how can I make <WindowsTargetPlatformVersion>
non-global so I can use the IDE to set it for each platform independently?
TIA!!
I need to have a different SDK based on the platform (Win32/x64/ARM64/etc..). Currently the .vcxproj
defines <WindowsTargetPlatformVersion>
as global
which means if I change it for one, it changes for all.
I can add a property sheet and manually add <WindowsTargetPlatformVersion>
but you can't use the UI to change it when needed.
So basically the question is, how can I make <WindowsTargetPlatformVersion>
non-global so I can use the IDE to set it for each platform independently?
TIA!!
Share Improve this question edited Feb 2 at 1:38 user3161924 asked Feb 1 at 22:41 user3161924user3161924 2,3291 gold badge23 silver badges42 bronze badges1 Answer
Reset to default 0Working with chatgpt, "we" came up with this PowerShell script that can move it from the global section to the other sections. Ensure you backup before attempting to use. Once the script is run on it you can manage the SDK like the platform tool-set.
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 2022Make WindowsTargetPlatformVersion (SDK) nonglobalStack Overflow
版权声明:本文标题:Visual Studio 2022 - Make WindowsTargetPlatformVersion (SDK) non-global? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741861058a2401627.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论