microsoft / Attestation-Client-Samples

MIT License
7 stars 6 forks source link

BUG FIX: Resolve Download Nuget Error Message when Configuring CMake #6

Closed carolinecreamer closed 3 months ago

carolinecreamer commented 3 months ago

Changes:

Next Steps:

Callouts for Review:

Resources Used:

Summary of Reasoning/Changes: I noticed that if you view the NuGet executable from the command line, it showed the executable name as "nuget.exe". If you look at the executable from the folder view outside of the command line, the name appears as "nuget". Because the NUGET_EXE variable is set in line 14 of CMakeLists.txt, I decided that line and the find_program macro was what was causing the issue. I looked up the CMake documentation for the find_program macro and saw that you can add additional "NAMES," so I changed line 14 from "find_program(NUGET_EXE NAMES nuget)" to "find_program(NUGET_EXE NAMES nuget nuget.exe)" because I assumed that the program was going to look for the .exe naming style that the command line was showing. That still wasn't working, so I found this Stack Overflow post where one of the commenters said to add hints to make it easier for the program to find the executable, so I changed line 14 from "find_program(NUGET_EXE NAMES nuget nuget.exe)" to "find_program(NUGET_EXE NAMES nuget nuget.exe HINTS ${CMAKE_CURRENT_SOURCE_DIR})" and that worked. I added a message statement (now deleted for code quality) to show me which naming style it did end up looking for and it showed the path as "C:/Users/cacreamer/Attestation-Client-Samples/nuget.exe", so it is looking for a file ending in .exe. To make it so that we don't have to ship "nuget.exe" with the samples, I found a macro called file() that allows you to download files via a URL, and added the capability to download the NuGet executable if it does not already exist within the customer's directory. I set the NuGet version in a variable called NUGET_VERSION to "latest" so that CMake downloads the most recent version, but this can be altered.