private static string TryGetRuntimeVersion()

in src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs [1048:1071]


        private static string TryGetRuntimeVersion(string path)
        {
            StringBuilder runtimeVersion = null;
            uint hresult = 0;
            uint actualBufferSize = 0;
            int bufferLength = 11; // 11 is the length of a runtime version and null terminator v2.0.50727/0

            do
            {
                runtimeVersion = new StringBuilder(bufferLength);
                hresult = NativeMethods.GetFileVersion(path, runtimeVersion, bufferLength, out actualBufferSize);
                bufferLength = bufferLength * 2;

            } while (hresult == NativeMethods.ERROR_INSUFFICIENT_BUFFER);

            if (hresult == NativeMethods.S_OK && runtimeVersion != null)
            {
                return runtimeVersion.ToString();
            }
            else
            {
                return String.Empty;
            }
        }