I am in a situation to call the “linker.exe” during the C# project (.csproj) build. If I am building the C# project with Visual studio 2019, then I want to execute the Visual Studio 2019 linker, or if I am building with Visual Studio 2022 then i want to execute the Visual Studio 2022 linker. I have tried below approaches, but all of them are failing to find the visual studio specific link.exe.
1- <Link task in msbuild – https://learn.microsoft.com/en-us/visualstudio/msbuild/link-task?view=vs-2022
Its failing, and throwing error – error MSB4018: Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: link.exe unexpectedly not a rooted path. Not able to locate the linker.exe.
2- Tried executing the linker.exe by executing the linker.exe using the <Exec Command=”link
Again, it throws error – ‘link’ is not recognized as an internal or external command,
Then I tried to initialize the Visual Studio environment by calling the vcvars64.bat batch file. This batch file is getting executed successfully, but after this If I call the <Exec Command=”link then it throws the error – ‘link’ is not recognized as an internal or external command.
So, it will be great if anybody knows how to execute the <Link task in msbuild without any errors.
Or
how to execute the linker.exe by calling the <Exec Command=”link.