简体   繁体   English

如何在 C# 项目的预构建和后构建事件中获取最新的 Windows sdk 版本路径?

[英]How to get latest windows sdk version path in prebuild and postbuild event of a C# project?

In my Visual Studio 2010 project we are running a prebuild and postbuildevent in a C# project as follows:在我的 Visual Studio 2010 项目中,我们在 C# 项目中运行 prebuild 和 postbuildevent,如下所示:

prebuildevent: "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\rc.exe" "$(ProjectDir)$(ProjectName).rc" prebuildevent: "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\rc.exe" "$(ProjectDir)$(ProjectName).rc"

postbuildevent: "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\mt.exe" -manifest "$(ProjectDir)$(TargetName).exe.manifest" -outputresource:"$(TargetDir)$(TargetFileName)";#1 postbuildevent: "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\mt.exe" -manifest "$(ProjectDir)$(TargetName).exe.manifest" -outputresource:"$(TargetDir )$(目标文件名)";#1

Where, path for rc.exe and mt.exe are hardcoded for Visual Studio 2010. Now we are migrating from Visual Studio 2010 to Visual Studio 2019.其中,rc.exe 和 mt.exe 的路径是为 Visual Studio 2010 硬编码的。现在我们正在从 Visual Studio 2010 迁移到 Visual Studio 2019。

In Visual Studio 2019, rc.exe and mt.exe are present in this path: "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.17763.0\\x86\\rc.exe" and "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.17763.0\\x86\\mt.exe".在 Visual Studio 2019 中,rc.exe 和 mt.exe 位于此路径中:“C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.17763.0\\x86\\rc.exe”和“C:\\ Program Files (x86)\\Windows Kits\\10\\bin\\10.0.17763.0\\x86\\mt.exe”。

But I cant use the above mentioned hardcoded path because as the Windows SDK Version gets changed for every SDK Version update.但是我不能使用上面提到的硬编码路径,因为每次 SDK 版本更新都会更改 Windows SDK 版本。

I found that we can use WindowsSdkverbinpath variable to get the latest windows sdk version path, but in my case this i am able to use it like $(WindowsSdkverbinpath) for c++ projects and it is resolving the path and c# projects i am not able to use it like in c++ projects.我发现我们可以使用WindowsSdkverbinpath变量来获取最新的 Windows sdk 版本路径,但在我的情况下,我可以像 $(WindowsSdkverbinpath) 一样使用它来处理 c++ 项目,并且它正在解析我无法解析的路径和 c# 项目像在 C++ 项目中一样使用它。

Purpose of searching WindowsSdkverbinpath is to use it in prebuild and postbuild events to access mt.exe and rc.exe搜索 WindowsSdkverbinpath 的目的是在 prebuild 和 postbuild 事件中使用它来访问 mt.exe 和 rc.exe

Please can anyone help me in getting the WindowsSdkverbinPath to use it in prebuild and postbuildevents for ac# project, Thanks in advance.请任何人都可以帮助我让 WindowsSdkverbinPath 在 ac# 项目的预构建和后构建事件中使用它,提前致谢。

I am afraid that you cannot get what you want in C# projects so far.恐怕到目前为止你在C#项目中得不到你想要的。

$(WindowsSdkverbinpath) and $(WindowsSdkDir) works on C++ projects rather than C# projects so far.到目前为止, $(WindowsSdkverbinpath)$(WindowsSdkDir)适用于C++项目而不是C#项目。

So you cannot get the latest version of Win10 kits by MSBuild on C# projects.因此,您无法通过MSBuildC#项目上获取最新版本的Win10 套件

If you want to get the latest version of Win10 kits on C# projects, you have to use the hardcoded approach.如果你想在C#项目上获得最新版本的Win10 工具包,你必须使用硬编码的方法。

Since opening every C# project and then have change the path of rc.exe and mt.exe might be inconvenient.由于打开每个 C# 项目然后更改rc.exemt.exe的路径可能不方便。

So I suggest you could use this:所以我建议你可以使用这个:

Suggestion建议

create a file called Directory.Build.props on your project folder在您的项目文件夹中创建一个名为Directory.Build.props的文件

在此处输入图片说明

Then add these content on that file:然后在该文件中添加这些内容:

<Project>
<PropertyGroup>

 <PreBuildEvent>C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86\rc.exe "$(ProjectDir)$(ProjectName).rc"</PreBuildEvent>
 <PostBuildEvent>"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\mt.exe" -manifest "$(ProjectDir)$(TargetName).exe.manifest" -outputresource:"$(TargetDir)$(TargetFileName)";#1</PostBuildEvent>

</PropertyGroup>
</Project>

And the file will be integrated into your project during build process.并且该文件将在构建过程中集成到您的项目中。 And you only have to modify the file and change the sdk version once and then save that file.您只需修改文件并更改 sdk 版本一次,然后保存该文件。 Copy that file into every C# project folder.将该文件复制到每个 C# 项目文件夹中。

It might be more convenient.可能会更方便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM