SDK与Windows 10更新同步及标准C++中WinRT使用的编译报错问题
Hey Richard, let's work through this compile error you're facing with C++/WinRT in VS2017 Community. You've already checked off the critical prerequisites—updating Windows 10 to 1803, installing the latest SDK, and setting up VS with the C++/WinRT package and templates—so let's narrow down the most likely issues:
Confirm C++/WinRT package and SDK version alignment
Sometimes extension updates don't sync perfectly with your installed SDK. OpenTools > Extensions and Updatesin VS2017, locate the C++/WinRT extension, note its version, then cross-check it against your Windows 10 SDK version (found inControl Panel > Programs and Featuresunder "Windows Software Development Kit"). If they don't match, reinstall the C++/WinRT extension targeted to your exact SDK version.Audit your project's configuration settings
Open your sample project's properties and verify these key areas:- Under
General, ensure theWindows SDK Versionis set to the latest one you installed (not a legacy version). - Under
C/C++ > General, check thatAdditional Include Directoriesincludes the C++/WinRT headers—this should be auto-populated, but updates can break this. Look for a path like$(SolutionDir)packages\Microsoft.Windows.CppWinRT.*\build\native\includeor the system-wide extension include path. - Under
Linker > Input, confirmwindowsapp.libis referenced (a requirement for UWP/C++/WinRT apps) and that no conflicting library references are present.
- Under
Do a clean, full rebuild
Visual Studio often caches old build artifacts after extension updates, which can cause unexpected errors. First, runBuild > Clean Solution, then manually delete thebinandobjfolders from your project directory. Finally, do a fullRebuild Solutionto compile everything from scratch.Rule out conflicting extensions or outdated VS components
If you have other C++/Windows runtime extensions installed (like older WRL tools), they might clash with C++/WinRT. Temporarily disable non-essential extensions and try compiling again. Also, make sure VS2017 is fully updated viaHelp > Check for Updates—core VS patches often fix extension compatibility bugs.Test with a fresh template project
Create a new C++/WinRT project using VS2017's built-in templates (e.g., a blank UWP app with C++/WinRT) and attempt to compile it. If this works, the issue is specific to your sample project—likely outdated code that doesn't match the newer C++/WinRT package version. Compare the working template's settings and code structure to your sample to spot discrepancies.
If you can share the exact error messages (compiler codes, line numbers, or specific warnings/errors), that would help zero in on the problem even quicker—for example, missing header files, unresolved symbols, or runtime version mismatches.
内容的提问来源于stack exchange,提问作者Richard Chambers

