我试图构建一个现有的驱动程序从windows 7到windows 10使用VS 2019。由于我现在使用的是wdk 10,所以无法获得用于设置wdk 10环境的setenv.bat文件。有人能帮我了解一下,在没有setenv.bat文件的情况下,我们如何设置wdk 10环境。

我试图找到一种使用makepackage.bat文件设置wdk 10环境的方法,但我没有得到任何合适的解决方案。
发布于 2022-11-23 17:02:03
您可以将以下代码放在.vcxproj文件的末尾。
...
<Target Name="SetMyEnvironmentVariables" AfterTargets="SetUserMacroEnvironmentVariables">
<SetEnv Condition="$(Platform) == 'x64'" Name="other_arch_spec" Value="amd64" Prefix="false" />
<SetEnv Condition="$(Platform) != 'x64'" Name="other_arch_spec" Value="i386" Prefix="false" />
</Target>
</Project>如果希望将环境变量永久存储在用户配置文件中或机器上,则将Target="Machine"或Target="User"添加到<SetEnv...中。有了这个添加,环境变量将在机器重新启动后存活下来。没有它--它将,而不是,在设置它的进程的终止中幸存下来。
您可以通过右键单击解决方案资源管理器中的项目名称并选择Properties -> Configuration Properties -> Build Events --> Pre-Build Event --> Command Line来验证是否确实设置了这个环境变量。
从All Platforms下拉列表中选择Platform。
...and在那里输入以下命令:set other_arch_spec
此set命令在生成项目时在Output window中显示此环境变量的值。如果你仔细看,它会在其他输出线之间。
...but这是一次黑客攻击。
实现这一目标的另一种方法是在从set other_arch_spec=amd64下拉列表中选择x64时使用命令行Platform设置环境变量,在从Platform下拉列表中选择x86时使用set other_arch_spec=i386。
也可以在那里调用批处理文件,而不是调用set other_arch_spec=...。
...but --这仍然是一个黑客,您应该努力避免使用批处理文件和环境变量--使用MsBuild/ Visual的变量。例如:
<PropertyGroup Condition=Condition="$(Platform) == 'x64'">
<other_arch_spec>amd64</other_arch_spec>
<MyOtherVariable>foo</MyOtherVariable>
</PropertyGroup>
<PropertyGroup Condition=Condition="$(Platform) != 'x64'">
<other_arch_spec>i386</other_arch_spec>
<MyOtherVariable>bar</MyOtherVariable>
</PropertyGroup>一旦设置了这些MsBuild/ Visual变量,就可以这样引用它们:
$(other_arch_spec)
$(MyOtherVariable)
这不仅适用于MsBuild的代码,也适用于Visual的IDE,即在属性页面中使用...just,比如内置宏,例如:$(ProjectDir)或$(ConfigurationName)等等。
https://stackoverflow.com/questions/74549463
复制相似问题