Ejemplo n.º 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)
                    {
                        break;
                    }
                }

                hasChanges = true;

                string value;
                bool   succeeded = HResultHelpers.SUCCEEDED(vsBuildMacroInfo.GetBuildMacroValue(addedMacro, out value)) && !String.IsNullOrEmpty(value);
                lock (_resolvedMacros) {
                    if (succeeded)
                    {
                        _resolvedMacros[addedMacro] = value;
                    }
                    else
                    {
                        _resolvedMacros.Remove(addedMacro);
                    }
                }
            }
            return(hasChanges);
        }
Ejemplo n.º 2
0
        private IReadOnlyDictionary <string, string> ResolveHeavyMacros(
            [NotNull] IEnumerable <string> macros,
            [NotNull] IProjectFile file
            )
        {
            var result = new Dictionary <string, string>();
            Lazy <IVsBuildMacroInfo> vsBuildMacroInfo = Lazy.Of(() => TryGetVsBuildMacroInfo(file), false);

            foreach (string macro in macros)
            {
                bool   succeeded = false;
                string value     = null;
                if (vsBuildMacroInfo.Value != null)
                {
                    succeeded = HResultHelpers.SUCCEEDED(vsBuildMacroInfo.Value.GetBuildMacroValue(macro, out value)) &&
                                !string.IsNullOrEmpty(value);
                }
                if (!succeeded)
                {
                    value     = MSBuildExtensions.GetStringValue(T4ResolutionUtils.TryGetVsHierarchy(file), macro, null);
                    succeeded = !string.IsNullOrEmpty(value);
                }

                if (succeeded)
                {
                    result[macro] = value;
                }
            }

            return(result);
        }
Ejemplo n.º 3
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);
        }