简体   繁体   中英

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:

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

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.

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".

But I cant use the above mentioned hardcoded path because as the Windows SDK Version gets changed for every SDK Version update.

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.

Purpose of searching WindowsSdkverbinpath is to use it in prebuild and postbuild events to access mt.exe and rc.exe

Please can anyone help me in getting the WindowsSdkverbinPath to use it in prebuild and postbuildevents for ac# project, Thanks in advance.

I am afraid that you cannot get what you want in C# projects so far.

$(WindowsSdkverbinpath) and $(WindowsSdkDir) works on C++ projects rather than C# projects so far.

So you cannot get the latest version of Win10 kits by MSBuild on C# projects.

If you want to get the latest version of Win10 kits on C# projects, you have to use the hardcoded approach.

Since opening every C# project and then have change the path of rc.exe and mt.exe might be inconvenient.

So I suggest you could use this:

Suggestion

create a file called Directory.Build.props on your project folder

在此处输入图片说明

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. Copy that file into every C# project folder.

It might be more convenient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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