Hi @Ollie ,
Welcome to Microsoft Q&A forum.
I don’t find a direct way which meet your requirements very well, but if you use some command lines(maybe PowerShell commands, CMD commands…) to edit the project file, then your requirements may meet. Besides, does creating a custom project template which set the correct target platform version by default meet your requirements?
I first think that, MSBuild command line may be work. It does work, for example msbuild.exe MyProject.sln -p:WindowsTargetPlatformVersion=10.0.22000.0
, but MSBuild is used for building the project as you know, and it doesn’t change the property settings, it just cover the project properties with the property set in command line while building. So this doesn’t meet your requirements.
I then consider if the Devenv command line work. I believe you have checked its related parameters and have tested them, so I agree with you, if /upgrade
doesn’t work, then other parameters are more inappropriate.
Actually, setting a specific project property, we usually consider modifying the saved property configurations in the project file(.xxproj file). So no direct way I think, you may consider writing some command lines or scripts to open and edit the property inside the project file, and use some command line tools to run these command lines/scripts.
If you consider using custom project templates then please refer to this document: How to: Create project templates.
BTW, I’m not sure, doesn’t VS set the two properties to the latest version by default when you generate the project?
- Update1:
For PowerShell command lines, you may try following:
$content=Get-Content -Path 'C:\myproject.vcxproj'
$newContent=$content -replace '10.0.19041.0', '10.0.22000.0'
$newContent|Set-Content -Path 'C:\myproject.vcxproj'
screenshot
Best Regards,
Tianyu
- If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.