Is it possible to change a Visual Studio projects Windows SDK version from the command line?

Ollie 41 Reputation points
2022-11-16T17:43:19.26+00:00

0

Once my Visual Studio project is generated it needs to upgrade the platform tool set and Windows SDK versions to the latest versions. I'm trying to find a way to upgrade the projects Windows SDK version from the command line, rather than in the GUI.

I currently using the following command:

devenv Myproject.sln /upgrade  

The problem is that this command only upgrades the platform tool set and not the Windows SDK version.

Is there a way to upgrade/change the Visual Studio projects Windows SDK version from the command line?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
3,137 questions
0 comments No comments
{count} votes

Accepted answer
  1. Tianyu Sun-MSFT 16,831 Reputation points Microsoft Vendor
    2022-11-17T06:57:58.827+00:00

    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

    261662-image.png

    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.

0 additional answers

Sort by: Most helpful