Exemplo n.º 1
0
        void AddPackagingPropsImport(MSBuildProject msproject)
        {
            MSBuildObject insertBefore = msproject.GetAllObjects().FirstOrDefault();

            msproject.AddNewImport(
                @"$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.props",
                @"Exists('$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.props')",
                insertBefore);
        }
Exemplo n.º 2
0
        public static void AddImport(
            this MSBuildProject project,
            string importedProjectFile,
            ImportLocation importLocation,
            string condition)
        {
            MSBuildObject before = GetInsertBeforeObject(project, importLocation);

            project.AddNewImport(importedProjectFile, condition, before);
        }
        internal protected override void OnWriteProject(ProgressMonitor monitor, MSBuildProject project)
        {
            base.OnWriteProject(monitor, project);

            HashSet <string> validProjitems = new HashSet <string> ();

            foreach (var r in Project.References.Where(rp => rp.ReferenceType == ReferenceType.Project))
            {
                var ip = r.GetItemsProjectPath();
                if (!string.IsNullOrEmpty(ip))
                {
                    ip = MSBuildProjectService.ToMSBuildPath(Project.ItemDirectory, ip);
                    validProjitems.Add(ip);
                    if (!project.Imports.Any(im => im.Project == ip))
                    {
                        // If there is already a Shared import, place the new import in the same location
                        MSBuildObject before = project.Imports.FirstOrDefault(i => i.Label == "Shared" && i.Project.EndsWith(".projitems"));
                        if (before == null)
                        {
                            var fsharpProject = project.ProjectTypeGuids.Contains("{F2A71F9B-5D33-465A-A702-920D77279786}");
                            if (fsharpProject)
                            {
                                //For F# use the first item group as the shared project files have to be listed first
                                before = project.ItemGroups.FirstOrDefault(i => i.Label != "Shared");
                            }
                            else
                            {
                                before = project.Imports.FirstOrDefault(i => i.Label != "Shared");
                            }
                        }

                        var im = project.AddNewImport(ip, beforeObject: before);
                        im.Label     = "Shared";
                        im.Condition = "Exists('" + ip + "')";
                    }
                }
            }
            foreach (var im in project.Imports.ToArray())
            {
                if (im.Label == "Shared" && im.Project.EndsWith(".projitems") && !(validProjitems.Contains(im.Project)))
                {
                    project.RemoveImport(im.Project);
                }
            }
        }
 void AddImport(string name, string condition, MSBuildObject before = null)
 {
     msbuildProject.AddNewImport(name, condition, before);
 }
Exemplo n.º 5
0
        public MSBuildPropertyGroup AddNewPropertyGroup(MSBuildObject insertAfter)
        {
            XmlElement elem = doc.CreateElement(null, "PropertyGroup", Schema);
            doc.DocumentElement.InsertAfter(elem, insertAfter.Element);

            return GetGroup(elem);
        }