VS2022 C++ pre-build event does not recognize 'sysnative'

ian bell 1 Reputation point
2022-06-22T20:18:45.723+00:00

I am upgrading from VS2019 to VS2022. I've got native C++ projects that run PowerShell scripts in pre-build events. The script locates PowerShell.exe using the SYSNATIVE virtual folder name. This works well in VS2017 and VS2019 but not in VS2022. The following generates an error in VS2022, specifically because of the virtual folder name SYSNATIVE:

"%systemroot%\sysnative\windowspowershell\v1.0\powershell.exe" -File "%powerShellScriptPath%" "$(SolutionDir)$(SolutionFileName)" "%resourceFilePath%"  

The error generated is MSB3073 and the corresponding message is "The system cannot find the path specified."

A work around solution is to replace SYSNATIVE with SysWOW64.

"%systemroot%\SysWow64\windowspowershell\v1.0\powershell.exe" -File "%powerShellScriptPath%" "$(SolutionDir)$(SolutionFileName)" "%resourceFilePath%"  

I am reluctant to add hacks (i.e. work around solution) into my projects. My question is, has anyone else encountered this problem and found a solution? If so, can you tell me what your solution is?

Thanks.

Ian

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,445 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,277 questions
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 38,856 Reputation points
    2022-06-22T20:35:20+00:00

    VS2017 and VS2019 are both 32-bit applications. VS2022 is a 64-bit application. Since build events in VS2017 and VS2019 are in WOW64 processes Sysnative is recognized as referring to the System32 folder (not SysWOW64) on a 64-bit system. The docs at file-system-redirector explain "WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access. This mechanism is flexible and easy to use, therefore, it is the recommended mechanism to bypass file system redirection. Note that 64-bit applications cannot use the Sysnative alias as it is a virtual directory not a real one.".

    If you want to use the 64-bit System32 folder then in VS2022 use System32 instead of Sysnative.

    2 people found this answer helpful.

  2. Limitless Technology 39,186 Reputation points
    2022-06-27T07:53:04.447+00:00

    Hi,

    Thank you for your question and reaching out. My name is Louie and I’d be more than happy to help you with your query.

    Based on the information you provided, it looks like you can try to reinstall VS2022 then try running the PowerShell script again. To remove all installations of Visual Studio 2022, and the Visual Studio Installer from your machine, uninstall it from Apps & Features.

    1. In Windows 10 or later, type Apps and Features in the "Type here to search" box.
    2. Find Visual Studio 2022.
    3. Choose Uninstall.
      4, Then, find Microsoft Visual Studio Installer.
    4. Choose Uninstall.

    To reinstall it, kindly go to this link for the steps and installer: https://visualstudio.microsoft.com/vs/

    If the reply was helpful, please don’t forget to Upvote or Accept as answer. Thank you!

    0 comments No comments