I’ve been building a library that requires some libs from windows. I managed to make it work but I’m struggling to find a proper solution.
PublicAdditionalLibraries.Add("C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/atlmfc/lib/x64/atls.lib");
PrivateIncludePaths.AddRange(
new string[] {
// ... add other private include paths required here ...
"C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/atlmfc/include"
}
);
As you can see, I’m pointing to a specific VS version and path, which is unacceptable.
Do you have any suggestions or can you point me to a proper example?
I didn’t know which library might have a similar requirement to compare their solution.
I know this question is old, but I had the exact same problem recently! So after spending a lot of time on it, this is my current solution.
Which involve using the VSAPPIDDIR environment variable that is defined at runtime. Then using path parsing, I’m able to retrieve the atls.lib that I want and add it to the linkage.
// Used to discover all `environment variables` setted during this, which make me discover `VSAPPIDDIR`.
//foreach (System.Collections.DictionaryEntry e in System.Environment.GetEnvironmentVariables())
//{
// System.Console.WriteLine(e.Key + ":" + e.Value);
//}
//System.Console.WriteLine(System.Environment.GetEnvironmentVariable("VSAPPIDDIR"));
System.IO.DirectoryInfo vsappdir = new System.IO.DirectoryInfo(System.Environment.GetEnvironmentVariable("VSAPPIDDIR"));
System.IO.DirectoryInfo vsdir = vsappdir.Parent.Parent;
System.IO.DirectoryInfo msvcDir = new System.IO.DirectoryInfo(Path.Combine(vsdir.FullName, "VC", "Tools", "MSVC"));
bool foundLib = false;
// Use `descending` order, in case we have multiple "version", prefer the latest.
foreach (System.IO.DirectoryInfo e in msvcDir.GetDirectories().OrderByDescending(p => p.Name))
{
System.IO.DirectoryInfo libDir = new System.IO.DirectoryInfo(Path.Combine(e.FullName, "atlmfc", "lib", "x64", "atls.lib"));
if (File.Exists(libDir.FullName))
{
PublicAdditionalLibraries.Add(libDir.FullName);
foundLib = true;
break;
}
}
if (!foundLib)
{
throw new BuildException("Could not found any atls.lib to link to");
}