Example #1
0
        /// <summary>
        /// Resolves new VS macros, like $(SolutionDir), found in include or assembly directives.
        /// </summary>
        /// <param name="macros">The list of macro names (eg SolutionDir) to resolve.</param>
        /// <returns>Whether at least one macro has been processed.</returns>
        private bool ResolveMacros([NotNull] IEnumerable <string> macros)
        {
            bool hasChanges = false;

            IVsBuildMacroInfo vsBuildMacroInfo = null;

            foreach (string addedMacro in macros)
            {
                if (vsBuildMacroInfo == null)
                {
                    vsBuildMacroInfo = TryGetVsBuildMacroInfo();
                    if (vsBuildMacroInfo == null)
                    {
                        Logger.LogError("Couldn't get IVsBuildMacroInfo");
                        break;
                    }
                }

                hasChanges = true;

                string value;
                bool   succeeded = HResultHelpers.SUCCEEDED(vsBuildMacroInfo.GetBuildMacroValue(addedMacro, out value)) && !String.IsNullOrEmpty(value);
                if (!succeeded)
                {
                    value     = MSBuildExtensions.GetStringValue(TryGetVsHierarchy(), addedMacro, null);
                    succeeded = !String.IsNullOrEmpty(value);
                }

                lock (_resolvedMacros) {
                    if (succeeded)
                    {
                        _resolvedMacros[addedMacro] = value;
                    }
                    else
                    {
                        _resolvedMacros.Remove(addedMacro);
                    }
                }
            }
            return(hasChanges);
        }