public static bool IsMSBuildIceBuilderInstalled(this IVsProject project)
        {
            var type = project.GetProjecTypeGuid();

            if (type.Equals(cppProjectGUID) || type.Equals(cppStoreAppProjectGUID) || type.Equals(csharpProjectGUID))
            {
                //
                // Find the full path of MSBuild Ice Builder props and target files and check they exists
                //
                var props = project.WithProject((MSProject msproject) =>
                {
                    return(msproject.Imports.Where(
                               import => import.ImportedProject.FullPath.EndsWith("zeroc.icebuilder.msbuild.props")).Select(
                               import => import.ImportedProject.FullPath).FirstOrDefault());
                });

                var targets = project.WithProject((MSProject msproject) =>
                {
                    return(msproject.Imports.Where(
                               import => import.ImportedProject.FullPath.EndsWith("zeroc.icebuilder.msbuild.targets")).Select(
                               import => import.ImportedProject.FullPath).FirstOrDefault());
                });
                return(!string.IsNullOrEmpty(props) && !string.IsNullOrEmpty(targets) && File.Exists(props) && File.Exists(targets));
            }
            return(false);
        }
        public static void AddCSharpGeneratedFiles(IVsProject project, string file)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var projectDir = project.GetProjectBaseDirectory();
            var dteproject = project.GetDTEProject();
            var fileset    = GetCsharpGeneratedFiles(project, dteproject, projectDir, file);

            //
            // First remove any generated items that are not in the
            // current generated items set for this Slice file
            //
            project.DeleteItems(project.WithProject((MSProject msproject) =>
            {
                return(msproject.AllEvaluatedItems.Where(
                           item =>
                {
                    if (item.ItemType.Equals("Compile") && item.HasMetadata("SliceCompileSource"))
                    {
                        if (item.GetMetadataValue("SliceCompileSource").Equals(fileset.filename))
                        {
                            return !fileset.sources.ContainsKey(Path.GetFullPath(Path.Combine(projectDir, item.EvaluatedInclude)));
                        }
                    }
                    return false;
                }).Select(item => Path.Combine(projectDir, item.EvaluatedInclude)).ToList());
            }));

            foreach (var entry in fileset.sources)
            {
                AddCSharpGeneratedItem(project, dteproject,
                                       projectDir,
                                       FileUtil.RelativePath(projectDir, fileset.filename),
                                       FileUtil.RelativePath(projectDir, entry.Key));
            }
        }
 public static List <string> GetIceBuilderItems(this IVsProject project)
 {
     return(project.WithProject((MSProject msproject) =>
                                msproject.Items.Where(item => item.ItemType.Equals("SliceCompile"))
                                .Select(item => item.EvaluatedInclude)
                                .ToList()));
 }
 public static string GetPropertyWithDefault(this IVsProject project, string name, string defaultValue)
 {
     return(project.WithProject((MSProject msproject) =>
     {
         return msproject.GetPropertyWithDefault(name, defaultValue);
     }));
 }
 public static string GetProperty(this IVsProject project, string name)
 {
     return(project.WithProject((MSProject msproject) =>
     {
         return msproject.GetProperty(name, true);
     }));
 }
Exemple #6
0
 public static bool HasProjectFlavor(this IVsProject project, string flavor)
 {
     return(project.WithProject((MSProject msproject) =>
     {
         return msproject.HasProjectFlavor(flavor);
     }, true));
 }
 public static string GetEvaluatedProperty(this IVsProject project, string name, string defaultValue)
 {
     return(project.WithProject((MSProject msproject) =>
     {
         var value = msproject.GetEvaluatedProperty(name);
         return string.IsNullOrEmpty(value) ? defaultValue : value;
     }));
 }
        public static bool IsIceBuilderGeneratedItem(this IVsProject project, string path)
        {
            var projectDir   = project.GetProjectBaseDirectory();
            var includeValue = FileUtil.RelativePath(projectDir, path);

            return(project.WithProject((MSProject msproject) =>
            {
                return msproject.AllEvaluatedItems.FirstOrDefault(
                    item =>
                {
                    return (item.ItemType.Equals("Compile") ||
                            item.ItemType.Equals("ClCompile") ||
                            item.ItemType.Equals("ClInclude")) &&
                    item.EvaluatedInclude.Equals(includeValue) &&
                    item.HasMetadata("SliceCompileSource");
                }) != null;
            }));
        }
 //
 // Check if IceBuilder 4.x is enabled
 //
 public static IceBuilderProjectType IsIceBuilderEnabled(IVsProject project)
 {
     if (project != null)
     {
         IceBuilderProjectType type = project.IsCppProject() ? IceBuilderProjectType.CppProjectType :
                                      project.IsCSharpProject() ? IceBuilderProjectType.CsharpProjectType : IceBuilderProjectType.None;
         if (type != IceBuilderProjectType.None)
         {
             return(project.WithProject((MSProject msproject) =>
             {
                 if (MSBuildUtils.IsIceBuilderEnabled(msproject))
                 {
                     return type;
                 }
                 return IceBuilderProjectType.None;
             }));
         }
     }
     return(IceBuilderProjectType.None);
 }
Exemple #10
0
        public bool Build(IVsProject project, BuildCallback buildCallback, BuildLogger buildLogger, string platform, string configuration)
        {
            return(project.WithProject((MSBuildProject msproject) =>
            {
                //
                // We need to set this before we acquire the build resources otherwise Msbuild
                // will not see the changes.
                //
                bool onlyLogCriticalEvents = msproject.ProjectCollection.OnlyLogCriticalEvents;
                msproject.ProjectCollection.Loggers.Add(buildLogger);
                msproject.ProjectCollection.OnlyLogCriticalEvents = false;

                uint cookie;
                int err = BuildManagerAccessor.AcquireBuildResources(VSBUILDMANAGERRESOURCE.VSBUILDMANAGERRESOURCE_DESIGNTIME |
                                                                     VSBUILDMANAGERRESOURCE.VSBUILDMANAGERRESOURCE_UITHREAD, out cookie);

                if (err != VSConstants.E_PENDING && err != VSConstants.S_OK)
                {
                    ErrorHandler.ThrowOnFailure(err);
                }

                if (err == VSConstants.E_PENDING)
                {
                    msproject.ProjectCollection.Loggers.Remove(buildLogger);
                    msproject.ProjectCollection.OnlyLogCriticalEvents = onlyLogCriticalEvents;

                    Dispatcher = Dispatcher.CurrentDispatcher;
                    BuildAvailableEvent = new ManualResetEvent(false);
                    BuildAvailableEvent.SafeWaitHandle = new SafeWaitHandle(BuildManagerAccessor.DesignTimeBuildAvailable, false);

                    Thread t = new Thread(() =>
                    {
                        BuildAvailableEvent.WaitOne();
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            Package.Instance.BuildNextProject();
                        }));
                    });
                    t.Start();
                    return false;
                }
                else
                {
                    try
                    {
                        Dictionary <string, string> properties = new Dictionary <string, string>();
                        properties["Platform"] = platform;
                        properties["Configuration"] = configuration;

                        BuildRequestData buildRequest = new BuildRequestData(
                            msproject.FullPath,
                            properties,
                            null,
                            new string[] { "SliceCompile" },
                            msproject.ProjectCollection.HostServices,
                            BuildRequestDataFlags.ProvideProjectStateAfterBuild |
                            BuildRequestDataFlags.IgnoreExistingProjectState |
                            BuildRequestDataFlags.ReplaceExistingProjectInstance);

                        BuildSubmission submission = BuildManager.DefaultBuildManager.PendBuildRequest(buildRequest);
                        ErrorHandler.ThrowOnFailure(BuildManagerAccessor.RegisterLogger(submission.SubmissionId, buildLogger));
                        Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() =>
                        {
                            buildCallback.BeginBuild(platform, configuration);
                        }));
                        submission.ExecuteAsync(s =>
                        {
                            Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() =>
                            {
                                msproject.ProjectCollection.Loggers.Remove(buildLogger);
                                msproject.ProjectCollection.OnlyLogCriticalEvents = onlyLogCriticalEvents;
                                BuildManagerAccessor.ReleaseBuildResources(cookie);
                                s.BuildManager.ResetCaches();
                                BuildManagerAccessor.UnregisterLoggers(s.SubmissionId);
                                buildCallback.EndBuild(s.BuildResult.OverallResult == BuildResultCode.Success);
                            }));
                        }, null);

                        return true;
                    }
                    catch (Exception)
                    {
                        msproject.ProjectCollection.Loggers.Remove(buildLogger);
                        msproject.ProjectCollection.OnlyLogCriticalEvents = onlyLogCriticalEvents;
                        BuildManagerAccessor.ReleaseBuildResources(cookie);
                        throw;
                    }
                }
            }));
        }
        public static void SetupGenerated(IVsProject project)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var projectDir = project.GetProjectBaseDirectory();

            //
            // Remove all CompileClCompile and ClInclude items that have an associted SliceCompileSource
            // item metadata that doesn't much any of the project SliceCompile items
            //
            if (project.IsCppProject())
            {
                project.DeleteItems(project.WithProject((MSProject msproject) =>
                {
                    var sliceCompile = msproject.AllEvaluatedItems.Where(
                        item => item.ItemType.Equals("SliceCompile")).Select(
                        item => item.EvaluatedInclude);

                    return(msproject.AllEvaluatedItems.Where(
                               item =>
                    {
                        if (item.ItemType.Equals("ClCompile") || item.ItemType.Equals("ClInclude"))
                        {
                            if (item.HasMetadata("SliceCompileSource"))
                            {
                                var value = item.GetMetadataValue("SliceCompileSource");
                                return !sliceCompile.Contains(value);
                            }
                        }
                        return false;
                    }).Select(item => Path.Combine(projectDir, item.EvaluatedInclude)).ToList());
                }));
            }
            else // C# project
            {
                project.DeleteItems(project.WithProject((MSProject msproject) =>
                {
                    var sliceCompile = msproject.AllEvaluatedItems.Where(
                        item => item.ItemType.Equals("SliceCompile")).Select(
                        item => item.EvaluatedInclude);

                    return(msproject.AllEvaluatedItems.Where(
                               item =>
                    {
                        if (item.ItemType.Equals("Compile"))
                        {
                            if (item.HasMetadata("SliceCompileSource"))
                            {
                                var value = item.GetMetadataValue("SliceCompileSource");
                                return !sliceCompile.Contains(value);
                            }
                        }
                        return false;
                    }).Select(item => Path.Combine(projectDir, item.EvaluatedInclude)).ToList());
                }));
            }

            // Now add any missing generated items
            var sliceItems = project.GetIceBuilderItems();

            foreach (var item in sliceItems)
            {
                AddGeneratedFiles(project, item);
            }
        }
        public static void AddCppGeneratedFiles(IVsProject project, string file)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var vcutil     = Package.Instance.VCUtil;
            var projectDir = project.GetProjectBaseDirectory();
            var dteproject = project.GetDTEProject();

            var fileset = GetCppGeneratedFiles(project, dteproject, vcutil, projectDir, file);

            var allConfigurations = new List <string>();

            foreach (EnvDTE.Configuration configuration in dteproject.ConfigurationManager)
            {
                allConfigurations.Add(ConfigurationString(configuration));
            }

            //
            // First remove any generated items that are not in the
            // current generated items set for this Slice file
            //
            project.DeleteItems(project.WithProject((MSProject msproject) =>
            {
                return(msproject.AllEvaluatedItems.Where(
                           item =>
                {
                    if (item.ItemType.Equals("ClCompile") && item.HasMetadata("SliceCompileSource"))
                    {
                        if (item.GetMetadataValue("SliceCompileSource").Equals(fileset.filename))
                        {
                            return !fileset.sources.ContainsKey(Path.GetFullPath(Path.Combine(projectDir, item.EvaluatedInclude)));
                        }
                    }
                    else if (item.ItemType.Equals("ClInclude") && item.HasMetadata("SliceCompileSource"))
                    {
                        if (item.GetMetadataValue("SliceCompileSource").Equals(fileset.filename))
                        {
                            return !fileset.headers.ContainsKey(Path.GetFullPath(Path.Combine(projectDir, item.EvaluatedInclude)));
                        }
                    }
                    return false;
                }).Select(item => Path.Combine(projectDir, item.EvaluatedInclude)).ToList());
            }));

            foreach (var entry in fileset.sources)
            {
                AddCppGeneratedItem(project, dteproject, vcutil,
                                    projectDir,
                                    FileUtil.RelativePath(projectDir, fileset.filename),
                                    FileUtil.RelativePath(projectDir, entry.Key),
                                    "Source Files",
                                    allConfigurations,
                                    entry.Value);
            }

            foreach (var entry in fileset.headers)
            {
                AddCppGeneratedItem(project, dteproject, vcutil,
                                    projectDir,
                                    FileUtil.RelativePath(projectDir, fileset.filename),
                                    FileUtil.RelativePath(projectDir, entry.Key), "Header Files", allConfigurations, entry.Value);
            }
        }