public static Dictionary LookupProjectProperties()

in src/Amazon.Common.DotNetCli.Tools/Utilities.cs [217:289]


        public static Dictionary<string, string> LookupProjectProperties(string projectLocation, string msBuildParameters, params string[] propertyNames)
        {
            var projectFile = FindProjectFileInDirectory(projectLocation);
            var properties = new Dictionary<string, string>();
            var arguments = new List<string>
            {
                "msbuild",
                projectFile,
                "-nologo",
                $"--getProperty:{string.Join(',', propertyNames)}"
            };

            if (!string.IsNullOrEmpty(msBuildParameters))
            {
                arguments.Add(msBuildParameters);
            }

            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "dotnet",
                    Arguments = string.Join(" ", arguments),
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    UseShellExecute = false,
                    CreateNoWindow = true
                }
            };
            try
            {
                process.Start();
                string output = process.StandardOutput.ReadToEnd().Trim();
                string error = process.StandardError.ReadToEnd();
                process.WaitForExit(5000);

                if (process.ExitCode == 0)
                {
                    if (propertyNames.Length == 1)
                    {
                        // If only one property was requested, the output is the direct value
                        properties[propertyNames[0]] = output;
                    }
                    else
                    {
                        // Multiple properties were requested, so we expect JSON output
                        using JsonDocument doc = JsonDocument.Parse(output);
                        JsonElement root = doc.RootElement;
                        JsonElement propertiesElement = root.GetProperty("Properties");

                        foreach (var property in propertyNames)
                        {
                            if (propertiesElement.TryGetProperty(property, out JsonElement propertyValue))
                            {
                                properties[property] = propertyValue.GetString();
                            }
                        }
                    }
                }
                else
                {
                    // Fallback to XML parsing
                    properties = LookupProjectPropertiesFromXml(projectFile, propertyNames);
                }
            }
            catch (Exception)
            {
                // Fallback to XML parsing
                properties = LookupProjectPropertiesFromXml(projectFile, propertyNames);
            }

            return properties;
        }