public async Task CreateInMemoryImport() {
            if (_unloadCancellationToken.IsCancellationRequested) {
                return;
            }

            using (var access = await _projectLockService.WriteLockAsync(_unloadCancellationToken)) {
                // A bit odd but we have to "check it out" prior to creating it to avoid some of the validations in chk CPS
                await access.CheckoutAsync(_inMemoryImportFullPath);

                // Now either open or create the in-memory file. Normally Create will happen, but in
                // a scenario where your project had previously failed to load for some reason, need to TryOpen
                // to avoid a new reason for a project load failure
                _inMemoryImport = ProjectRootElement.TryOpen(_inMemoryImportFullPath, access.ProjectCollection);
                if (_inMemoryImport != null) {
                    // The file already exists. Scrape it out so we don’t add duplicate items.
                    _inMemoryImport.RemoveAllChildren();
                } else {
                    // The project didn’t already exist, so create it, and then mark the evaluated project dirty
                    // so that MSBuild will notice. This step isn’t necessary if the project was already in memory.
                    _inMemoryImport = CreateEmptyMsBuildProject(_inMemoryImportFullPath, access.ProjectCollection);

                    // Note that we actually need to mark every project evaluation dirty that is already loaded.
                    await ReevaluateLoadedConfiguredProjects(_unloadCancellationToken, access);
                }

                _filesItemGroup = _inMemoryImport.AddItemGroup();
                _directoriesItemGroup = _inMemoryImport.AddItemGroup();
                _temporaryAddedItemGroup = _inMemoryImport.AddItemGroup();
            }
        }
Exemple #2
0
        internal static void generateFiles(Project p, PGOptions opts1, ProjectItemGroupElement pige)
        {
            Dictionary<string, string> tmp = new Dictionary<string, string>();
            WinDataProvider wdp = new WinDataProvider(WIN_NAME, opts1.projectNamespace, opts1.xamlType == XamlWindowType.RegularWindow);
            AppDataProvider apd = new AppDataProvider(wdp.fileName, opts1.projectNamespace);
            HomeDataProvider hdp = null;
            string tmp2;

            XamlFileGenerator.generateFile(apd, opts1);
            XamlFileGenerator.generateFile(wdp, opts1);

            if (opts1.xamlType == XamlWindowType.NavigationWindow) {
                hdp = new HomeDataProvider(wdp.homePage, opts1.projectNamespace);
                XamlFileGenerator.generateFile(hdp, opts1);
                generatePageAndModel(pige, hdp);
            }

            if (!string.IsNullOrEmpty(tmp2 = wdp.viewModelName) && File.Exists(tmp2)) {
                generateCompile(pige, tmp2);
            }

            generateApp(pige, apd);
            generatePage(pige, wdp);

            if (opts1.xamlPages.Count > 0) {
                GeneralPage gp;
                foreach (string aPageName in opts1.xamlPages) {
                    gp = new GeneralPage(aPageName, opts1.projectNamespace);
                    XamlFileGenerator.generateFile(gp, opts1);
                    generatePageAndModel(pige, gp);
                }
            }
        }
Exemple #3
0
        static void generateDependentCompile(ProjectItemGroupElement pige, string fname, string depName)
        {
            IDictionary<string, string> tmp = new Dictionary<string, string>();

            if (!string.IsNullOrEmpty(depName))
                tmp.Add("DependentUpon", Path.GetFileName(depName));
            tmp.Add("SubType", "Code");
            generateCompile(pige, fname, tmp);
        }
		internal ProjectItemGroupTaskInstance (ProjectItemGroupElement xml)
		{
			condition = xml.Condition;
			condition_location = xml.ConditionLocation;
			//this.FullPath = fullPath;
			location = xml.Location;
			
			Items = xml.Items.Select (item => new ProjectItemGroupTaskItemInstance (item)).ToArray ();
		}
 void GenerateCompileIncludes (ProjectItemGroupElement itemGroup)
 {
         foreach (var include in new[] { "Test.cs", "Test2.cs", "Test3.cs" }) {
                 itemGroup.AddItem ("Compile", ProjectCollection.Escape (include),
                         new[] { new KeyValuePair<string, string> ("SubType", "Code") });
         }
         foreach (var resource in new[] { "Test.resx", "Test2.resx", "Test3.resx" }) {
                 itemGroup.AddItem ("EmbeddedResource", ProjectCollection.Escape (resource),
                         new[] { new KeyValuePair<string, string> ("LogicalName", "Name.Space.Test") });
         }
 }
Exemple #6
0
 internal static void generateMainFiles(Project p, PGOptions opts, ProjectItemGroupElement pige2)
 {
     switch (opts.projectType) {
         case ProjectType.WindowsForm: generateForms(pige2, opts); break;
         case ProjectType.ConsoleApp: generateMain(pige2, opts); break;
         case ProjectType.ClassLibrary: generateLib(pige2, opts); break;
         case ProjectType.XamlApp: generateXaml(pige2, opts); break;
         default:
             throw new InvalidOperationException("unhandled " + opts.projectType.GetType().Name + ": " + opts.projectType);
     }
 }
 void GenerateReferences (ProjectItemGroupElement itemGroup)
 {
         foreach (var reference in new[] { "Test.dll", "Test2.dll", "Test3.dll" }) {
                 var name = Path.GetFileNameWithoutExtension (reference);
                 itemGroup.AddItem ("Reference", name, new[] {
                         new KeyValuePair<string, string> ("Name", name),
                         new KeyValuePair<string, string> ("HintPath",
                                 ProjectCollection.Escape (reference)) });
         }
         foreach (var reference in new[] { "mscorlib", "System", "System.Xml" }) {
                 itemGroup.AddItem ("Reference", reference);
         }
 }
Exemple #8
0
        static void generateApp(ProjectItemGroupElement pige, IXamlFileGenerationData ixfgd)
        {
            #if true
            generateNode(pige, ixfgd.xamlName, "Generator", "ApplicationDefinition");
            #else
            IDictionary<string, string> tmp = new Dictionary<string, string>();

            tmp.Add("Generator", "MSBuild:Compile");
            tmp.Add("SubType", "Generator");
            pige.AddItem("ApplicationDefinition", ixfgd.xamlName, tmp);
            Debug.Print("Adding: " + ixfgd.xamlName);
            #endif
            generateDependentCompile(pige, ixfgd.codeBehindName, ixfgd.xamlName);
        }
        static void addProjCfg(ProjectItemGroupElement v1, string cfg, string plat)
        {
            ProjectItemElement pie = v1.AddItem("ProjectConfiguration", cfg + "|" + plat);

            pie.AddMetadata("Configuration", cfg);
            pie.AddMetadata("Platform", plat);
        }
 static void fakeC(ProjectItemGroupElement pige)
 {
     pige.AddItem("ClCompile", "fake.c");
 }
Exemple #11
0
 /// <summary>
 /// Initialize a parented ProjectItemElement instance
 /// </summary>
 internal ProjectItemElement(XmlElementWithLocation xmlElement, ProjectItemGroupElement parent, ProjectRootElement containingProject)
     : base(xmlElement, parent, containingProject)
 {
     ErrorUtilities.VerifyThrowArgumentNull(parent, nameof(parent));
 }
        internal ProjectItemElement LookupItem(ProjectItemGroupElement parent, string name, string condition = null) {
            ProjectItemElement property = null;

            var label = Pivots.GetExpressionLabel(condition);
            name = name.Replace(".", "_");

            if(string.IsNullOrEmpty(condition)) {
                property = parent.Items.FirstOrDefault(each => name == each.ItemType && string.IsNullOrEmpty(each.Condition));
                if(property != null) {
                    return property;
                }
                return parent.AddItem(name, "UNUSED");
            }

            var conditionExpression = Pivots.GetMSBuildCondition(Name, condition);
            property = parent.Items.FirstOrDefault(each => name == each.ItemType && each.Condition == conditionExpression);
            if(property != null) {
                return property;
            }

            property = parent.AddItem(name, "UNUSED");

            property.Label = label;
            property.Condition = conditionExpression;
            
            return property;
        }
        private void RemoveItem(ProjectItemGroupElement parent, Dictionary<string, ProjectItemElement> items, string path) {
            ProjectItemElement item;
            if (!items.TryGetValue(path, out item)) {
                return;
            }

            parent.RemoveChild(item);
            items.Remove(path);
        }
        /// <summary>
        /// Processes the &lt;Service&gt; element, and add an appropriate reference
        /// items to the startupServicesItemGroup.
        /// </summary>
        /// <owner>RGoel</owner>
        private void ProcessServiceElement
            (
            XmlElementWithLocation      serviceElement,
            ProjectItemGroupElement startupServicesItemGroup
            )
        {
            // Make sure this is the <Service> element.
            error.VerifyThrow((serviceElement != null) &&
                (serviceElement.Name == VSProjectElements.service),
                "Expected <Service> element.");

            // Make sure the caller has already created an ProjectItemGroupElement for us to
            // put the new items in.
            error.VerifyThrow(startupServicesItemGroup != null, "Received null ProjectItemGroupElement");

            // Get the required "ID" attribute.
            string id = serviceElement.GetAttribute(VSProjectAttributes.id);
            ProjectErrorUtilities.VerifyThrowInvalidProject((id != null) && (id.Length > 0), serviceElement.Location,
                "MissingAttribute", VSProjectAttributes.id, VSProjectElements.service);
            // Remove the "ID" attribute, so it doesn't show up in our loop later.
            serviceElement.RemoveAttribute(VSProjectAttributes.id);

            // The <Service> element gets converted to XMake as an item of type "Service".
            // The "ID" attribute becomes the "Include" for the new item.  For
            // example,
            // -----------------------------------------------------------------------
            // Everett format:
            // ===============
            //    <Service ID = "ABCD1234-78F4-4F98-AFD6-720DA6E648A2" />
            // -----------------------------------------------------------------------
            // XMake format:
            // =============
            //    <Service Include="ABCD1234-78F4-4F98-AFD6-720DA6E648A2" />
            // -----------------------------------------------------------------------
            startupServicesItemGroup.AddItem(XMakeProjectStrings.service, ProjectCollection.Escape(id));

            // There should be no other attributes on the <Service> element (besides
            // "ID" which we already took care of).  But loop through them
            // anyway, so we can emit a useful error message.
            foreach (XmlAttributeWithLocation serviceAttribute in serviceElement.Attributes)
            {
                ProjectErrorUtilities.VerifyThrowInvalidProject(false, serviceAttribute.Location, "UnrecognizedAttribute",
                    serviceAttribute.Name, VSProjectElements.service);
            }

            // There should be no children of the <Service> element.
            ProjectXmlUtilities.VerifyThrowProjectNoChildElements(serviceElement);
        }
Exemple #15
0
        /// <summary>
        /// Parse a ProjectItemElement
        /// </summary>
        private ProjectItemElement ParseProjectItemElement(XmlElementWithLocation element, ProjectItemGroupElement parent)
        {
            ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnItem);

            bool belowTarget = parent.Parent is ProjectTargetElement;

            string itemType = element.Name;
            string include = element.GetAttribute(XMakeAttributes.include);
            string exclude = element.GetAttribute(XMakeAttributes.exclude);
            string remove = element.GetAttribute(XMakeAttributes.remove);
            string update = element.GetAttribute(XMakeAttributes.update);

            var exclusiveItemOperation = "";
            int exclusiveAttributeCount = 0;
            if (element.HasAttribute(XMakeAttributes.include))
            {
                exclusiveAttributeCount++;
                exclusiveItemOperation = XMakeAttributes.include;
            }
            if (element.HasAttribute(XMakeAttributes.remove))
            {
                exclusiveAttributeCount++;
                exclusiveItemOperation = XMakeAttributes.remove;
            }
            if (element.HasAttribute(XMakeAttributes.update))
            {
                exclusiveAttributeCount++;
                exclusiveItemOperation = XMakeAttributes.update;
            }

            //  At most one of the include, remove, or update attributes may be specified
            if (exclusiveAttributeCount > 1)
            {
                XmlAttributeWithLocation errorAttribute = remove.Length > 0 ? (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.remove] : (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.update];
                ProjectErrorUtilities.ThrowInvalidProject(errorAttribute.Location, "InvalidAttributeExclusive");
            }

            // Include, remove, or update must be present unless inside a target
            ProjectErrorUtilities.VerifyThrowInvalidProject(exclusiveAttributeCount == 1 || belowTarget, element.Location, "MissingRequiredAttribute", exclusiveItemOperation, itemType);

            // Exclude must be missing, unless Include exists
            ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute(exclude.Length == 0 || include.Length > 0, (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.exclude]);

            // If we have an Include attribute at all, it must have non-zero length
            ProjectErrorUtilities.VerifyThrowInvalidProject(include.Length > 0 || element.Attributes[XMakeAttributes.include] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.include, itemType);

            // If we have a Remove attribute at all, it must have non-zero length
            ProjectErrorUtilities.VerifyThrowInvalidProject(remove.Length > 0 || element.Attributes[XMakeAttributes.remove] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.remove, itemType);

            // If we have an Update attribute at all, it must have non-zero length
            ProjectErrorUtilities.VerifyThrowInvalidProject(update.Length > 0 || element.Attributes[XMakeAttributes.update] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.update, itemType);

            XmlUtilities.VerifyThrowProjectValidElementName(element);
            ProjectErrorUtilities.VerifyThrowInvalidProject(XMakeElements.IllegalItemPropertyNames[itemType] == null, element.Location, "CannotModifyReservedItem", itemType);

            ProjectItemElement item = new ProjectItemElement(element, parent, _project);

            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, item);

                item.AppendParentedChildNoChecks(metadatum);
            }

            return item;
        }
 private Task RemoveItems(ProjectItemGroupElement parent, Dictionary<string, ProjectItemElement> items, string directoryName, ProjectWriteLockReleaser access) {
     return RemoveItems(parent, items, items.Keys.Where(f => f.StartsWithIgnoreCase(directoryName)).ToList(), access);
 }
        /// <summary>
        /// Given an element corresponding to a .NET Assembly reference, create the appropriate element in the new project
        /// </summary>
        /// <param name="referenceElement"></param>
        /// <param name="referencesItemGroup"></param>
        /// <param name="referenceName"></param>
        /// <returns></returns>
        private ProjectItemElement ConvertAssemblyReference(XmlElementWithLocation referenceElement, ProjectItemGroupElement referencesItemGroup, string referenceName)
        {
            ProjectItemElement newReferenceItem;
            // This is a regular .NET assembly reference.

            // This gets added as a new XMake item of type "Reference".  The "Include"
            // attribute is the assembly name, and all the other attributes remain
            // the same.  For example,
            // -----------------------------------------------------------------------
            // Everett format:
            // ===============
            //    <Reference
            //        Name = "System.Xml"
            //        AssemblyName = "System.Xml"
            //        HintPath = "..\..\binaries\x86chk\bin\i386\System.Xml.dll"
            //    />
            // -----------------------------------------------------------------------
            // XMake format:
            // =============
            //    <Reference Include="System.Xml">
            //          <Name>System.Xml</Name>
            //          <HintPath>..\..\binaries\x86chk\bin\i386\System.Xml.dll</HintPath>
            //    </Reference>
            // -----------------------------------------------------------------------

            // Get the "AssemblyName" attribute.  If not found, just use the value from the
            // "Name" attribute.  This is what the project loading code does in VS.
            string assemblyName = referenceElement.GetAttribute(VSProjectAttributes.assemblyName);
            if ((assemblyName == null) || (assemblyName.Length == 0))
            {
                assemblyName = referenceName;
            }
            else
            {
                // Remove the "AssemblyName" attribute so we don't add it again at
                // the end.
                referenceElement.RemoveAttribute(VSProjectAttributes.assemblyName);
            }

            // MyType should only be added when System.Windows.Forms is present. If this
            // reference is seen, then set a flag so we can later add MyType.
            if (0 == String.Compare("System.Windows.Forms", assemblyName, StringComparison.OrdinalIgnoreCase))
            {
                hasWindowsFormsReference = true;
            }

            // Remove hint paths that we think are to RTM or Everett framework assemblies
            string hintPath = referenceElement.GetAttribute(VSProjectAttributes.hintPath);
            if (hintPath != null)
            {
                hintPath = hintPath.ToUpper(CultureInfo.InvariantCulture);
                if (hintPath.IndexOf(LegacyFrameworkPaths.RTMFrameworkPath, StringComparison.Ordinal) != -1 ||
                    hintPath.IndexOf(LegacyFrameworkPaths.EverettFrameworkPath, StringComparison.Ordinal) != -1 ||
                    hintPath.IndexOf(LegacyFrameworkPaths.JSharpRTMFrameworkPath, StringComparison.Ordinal) != -1)
                {
                    referenceElement.RemoveAttribute(VSProjectAttributes.hintPath);
                }
            }

            newReferenceItem = referencesItemGroup.AddItem(XMakeProjectStrings.reference, ProjectCollection.Escape(assemblyName));
            return newReferenceItem;
        }
Exemple #18
0
        /// <summary>
        /// Parse a ProjectItemElement
        /// </summary>
        private ProjectItemElement ParseProjectItemElement(XmlElementWithLocation element, ProjectItemGroupElement parent)
        {
            ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnItem);

            bool belowTarget = parent.Parent is ProjectTargetElement;

            string itemType = element.Name;
            string include  = element.GetAttribute(XMakeAttributes.include);
            string exclude  = element.GetAttribute(XMakeAttributes.exclude);
            string remove   = element.GetAttribute(XMakeAttributes.remove);

            // Remove must be missing, unless inside a target and Include is missing
            ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute((remove.Length == 0 || (belowTarget && include.Length == 0)), (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.remove]);

            // Include must be present, unless inside a target
            ProjectErrorUtilities.VerifyThrowInvalidProject(include.Length > 0 || belowTarget, element.Location, "MissingRequiredAttribute", XMakeAttributes.include, itemType);

            // Exclude must be missing, unless Include exists
            ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute(exclude.Length == 0 || include.Length > 0, (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.exclude]);

            // If we have an Include attribute at all, it must have non-zero length
            ProjectErrorUtilities.VerifyThrowInvalidProject(include.Length > 0 || element.Attributes[XMakeAttributes.include] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.include, itemType);

            XmlUtilities.VerifyThrowProjectValidElementName(element);
            ProjectErrorUtilities.VerifyThrowInvalidProject(XMakeElements.IllegalItemPropertyNames[itemType] == null, element.Location, "CannotModifyReservedItem", itemType);

            ProjectItemElement item = new ProjectItemElement(element, parent, _project);

            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, item);

                item.AppendParentedChildNoChecks(metadatum);
            }

            return(item);
        }
Exemple #19
0
 static void generatePageAndModel(ProjectItemGroupElement pige, IXamlFileGenerationData hdp)
 {
     generatePage(pige, hdp);
     generateCompile(pige, hdp.viewModelName);
 }
Exemple #20
0
        static void generatePage(ProjectItemGroupElement pige, IXamlFileGenerationData ixfgd)
        {
            //            string genType = "Designer";
            //          string itemType = "Page";

            generateNode(pige, ixfgd.xamlName, "Designer", "Page");
            generateDependentCompile(pige, ixfgd.codeBehindName, ixfgd.xamlName);
        }
Exemple #21
0
 /// <summary>
 /// Initialize a parented ProjectItemElement instance
 /// </summary>
 internal ProjectItemElement(XmlElementWithLocation xmlElement, ProjectItemGroupElement parent, ProjectRootElement containingProject)
     : base(xmlElement, parent, containingProject)
 {
     ErrorUtilities.VerifyThrowArgumentNull(parent, "parent");
 }
 static void fakeH(ProjectItemGroupElement pige)
 {
     pige.AddItem("ClInclude", "fake.h");
 }
        /// <summary>
        /// Given an element corresponding to a P2P reference, create the appropriate element in the new project
        /// </summary>
        /// <param name="referenceElement"></param>
        /// <param name="referencesItemGroup"></param>
        /// <param name="referenceName"></param>
        /// <param name="referencedProjectGuid"></param>
        /// <returns></returns>
        private ProjectItemElement ConvertProjectToProjectReference(XmlElementWithLocation referenceElement, ProjectItemGroupElement referencesItemGroup, string referenceName, ref string referencedProjectGuid)
        {
            ProjectItemElement newReferenceItem;
            // This is a project-to-project reference.

            // This gets added as a new XMake item of type "ProjectReference".
            // The "Include" attribute should be the relative path from the
            // current project to the referenced project file.  For example,
            // -----------------------------------------------------------------------
            // Everett format:
            // ===============
            //    <Reference
            //        Name = "XMakeTasks"
            //        Project = "{44342961-78F4-4F98-AFD6-720DA6E648A2}"
            //        Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
            //    />
            // -----------------------------------------------------------------------
            // XMake format:
            // =============
            //    <ProjectReference Include = "..\XMakeTasks\XMakeTasks.csproj">
            //          <Name>XMakeTasks</Name>
            //          <Project>{44342961-78F4-4F98-AFD6-720DA6E648A2}</Project>
            //          <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
            //    </ProjectReference>
            // -----------------------------------------------------------------------

            // Apparently, sometimes project reference guids contain additional goo with relative project path.
            // Just strip it off. The project system does the same thing, and by doing this early we make
            // sure that we have the correct guid attribute in the project file and ResolveNonMSBuildReferences
            // does not complain about invalid characters there which causes all the references to fail to resolve.
            int barIndex = referencedProjectGuid.IndexOf('|');
            if (barIndex != -1)
            {
                referencedProjectGuid = referencedProjectGuid.Remove(barIndex);
                referenceElement.SetAttribute(VSProjectAttributes.project, referencedProjectGuid);
            }

            string pathToReferencedProject = this.GetRelativePathToReferencedProject(referencedProjectGuid);

            if (pathToReferencedProject != null)
            {
                // For VSD Projects, we want to transform all Everett ( .csdproj & .vbdproj ) project 2 project references into
                // Whidbey ( .csproj & .vbproj ) references.
                if (0 == String.Compare(Path.GetExtension(pathToReferencedProject),
                                        XMakeProjectStrings.csdprojFileExtension,
                                        StringComparison.OrdinalIgnoreCase))
                {
                    pathToReferencedProject = Path.ChangeExtension(pathToReferencedProject, XMakeProjectStrings.csprojFileExtension);
                }
                else if (0 == String.Compare(Path.GetExtension(pathToReferencedProject),
                                             XMakeProjectStrings.vbdprojFileExtension,
                                             StringComparison.OrdinalIgnoreCase))
                {
                    pathToReferencedProject = Path.ChangeExtension(pathToReferencedProject, XMakeProjectStrings.vbprojFileExtension);
                }
            }

            // Add a new item to XMake of type "ProjectReference".  If we were able to find
            // the relative path to the project, use it for the "Include", otherwise just use
            // the project name.
            string value = (pathToReferencedProject != null) ? pathToReferencedProject : referenceName;
            newReferenceItem = referencesItemGroup.AddItem(XMakeProjectStrings.projectReference, ProjectCollection.Escape(value));
            return newReferenceItem;
        }
 static void fakeNone(ProjectItemGroupElement pige)
 {
     pige.AddItem("None", "fake.txt");
 }
        /// <summary>
        /// Processes the &lt;File&gt; element, and adds an appropriate item to the
        /// filesItemGroup.
        /// </summary>
        /// <owner>RGoel</owner>
        private void ProcessFileElement
            (
            XmlElementWithLocation      fileElement,
            ProjectItemGroupElement filesItemGroup
            )
        {
            // Make sure this is the <File> element.
            error.VerifyThrow((fileElement != null) &&
                (fileElement.Name == VSProjectElements.file),
                "Expected <File> element.");

            // Make sure the caller has already created an ProjectItemGroupElement for us to
            // put the new items in.
            error.VerifyThrow(filesItemGroup != null, "Received null ProjectItemGroupElement");

            // Get the required "RelPath" attribute.
            string relPath = fileElement.GetAttribute(VSProjectAttributes.relPath);
            ProjectErrorUtilities.VerifyThrowInvalidProject((relPath != null) && (relPath.Length > 0),
                fileElement.Location, "MissingAttribute", VSProjectAttributes.relPath, VSProjectElements.file);
            // Remove the "RelPath" attribute, so we don't end up adding it twice.
            fileElement.RemoveAttribute(VSProjectAttributes.relPath);

            // Get the "Link" attribute.  This is for linked items only.
            string linkPath = fileElement.GetAttribute(VSProjectAttributes.link);
            // Remove the "Link" attribute, so we don't end up adding it twice.
            fileElement.RemoveAttribute(VSProjectAttributes.link);

            // Get the "BuildAction" attribute.  If it doesn't exist, figure out
            // what the build action is based on the file extension.  This is
            // what the project loading code does in VS.
            string buildAction = fileElement.GetAttribute(VSProjectAttributes.buildAction);
            if ((buildAction == null) || (buildAction.Length == 0))
            {
                buildAction = VSProjectAttributes.buildActionNone;
            }
            // Remove the "BuildAction" attribute, so we don't end up adding it twice.
            fileElement.RemoveAttribute(VSProjectAttributes.buildAction);

            ProjectItemElement newFileItem;

            // Bug Whidbey #248965. If a .resx file is completely empty, do not include a reference
            // to it in the upgraded project file.
            if (!
                (0 == String.Compare(Path.GetExtension(relPath), ".resx", StringComparison.OrdinalIgnoreCase)
                 && IsFilePresentButEmpty(relPath, linkPath))
               )
            {

                // Add the new item to XMake.
                if ((linkPath == null) || (linkPath.Length == 0))
                {
                    // Normal item.

                    // The <File> element gets converted to XMake as a new item, where
                    // the item type is the BuildAction, and the "Include" contains
                    // the relative path to the item.  For
                    // example,
                    // -----------------------------------------------------------------------
                    // Everett format:
                    // ===============
                    //    <File
                    //        RelPath = "Properties\PropertyGroupCollection.cs"
                    //        SubType = "Code"
                    //        BuildAction = "Compile"
                    //    />
                    // -----------------------------------------------------------------------
                    // XMake format:
                    // =============
                    //    <Compile Include = "Properties\PropertyGroupCollection.cs">
                    //          <SubType>Code</SubType>
                    //    </Compile>
                    // -----------------------------------------------------------------------
                    newFileItem = filesItemGroup.AddItem(buildAction, ProjectCollection.Escape(relPath));
                }
                else
                {
                    // Linked item.

                    // The <File> element gets converted to XMake as a new item, where
                    // the item type is the BuildAction, the "Include" contains
                    // the physical relative path to the item, and the non-XMake "Link"
                    // attribute contains the project-relative path for item (for display
                    // purposes in the Solution Explorer).  For example,
                    // -----------------------------------------------------------------------
                    // Everett format:
                    // ===============
                    //    <File
                    //        RelPath = "Properties\PropertyGroupCollection.cs"
                    //        Link = "c:\Rajeev\External\PropertyGroupCollection.cs"
                    //        SubType = "Code"
                    //        BuildAction = "Compile"
                    //    />
                    // -----------------------------------------------------------------------
                    // XMake format:
                    // =============
                    //    <Compile Include = "c:\Rajeev\External\PropertyGroupCollection.cs">
                    //          <Link>Properties\PropertyGroupCollection.cs</Link>
                    //          <SubType>Code</SubType>
                    //    </Compile>
                    // -----------------------------------------------------------------------
                    newFileItem = filesItemGroup.AddItem(buildAction, ProjectCollection.Escape(linkPath));
                    newFileItem.AddMetadata(XMakeProjectStrings.link, ProjectCollection.Escape(relPath));
                }

                // Add all the rest of the attributes on the <File> element to the new
                // XMake item.
                foreach (XmlAttribute fileAttribute in fileElement.Attributes)
                {
                    newFileItem.AddMetadata(fileAttribute.Name, ProjectCollection.Escape(fileAttribute.Value));
                }

                // If this is a VSD(devices) project and we're dealing with a content file,
                // mark it to copy if newer.
                if ( ( ( ( this.language == VSProjectElements.ECSharp ) ||
                         ( this.language == VSProjectElements.EVisualBasic ) ) ) &&
                     ( 0 == String.Compare ( buildAction, XMakeProjectStrings.content, StringComparison.OrdinalIgnoreCase ) ) )
                {
                    newFileItem.AddMetadata ( XMakeProjectStrings.copytooutput,
                                              XMakeProjectStrings.preservenewest );
                }
            }
            else
            {
                string warning = ResourceUtilities.FormatString(
                    AssemblyResources.GetString("EmptyResxRemoved"),
                    relPath);
                conversionWarnings.Add(warning);
            }

            // There should be no children of the <File> element.
            ProjectXmlUtilities.VerifyThrowProjectNoChildElements(fileElement);
        }
 private async Task RemoveItems(ProjectItemGroupElement parent, Dictionary<string, ProjectItemElement> items, IReadOnlyCollection<string> itemsToRemove, ProjectWriteLockReleaser access) {
     await access.CheckoutAsync(itemsToRemove);
     foreach (var path in itemsToRemove) {
         RemoveItem(parent, items, path);
     }
 }
Exemple #27
0
        static void generateNode(ProjectItemGroupElement pige, string fname, string genType, string itemType)
        {
            IDictionary<string, string> tmp = new Dictionary<string, string>();

            tmp.Add("Generator", "MSBuild:Compile");
            tmp.Add("SubType", genType);
            pige.AddItem(itemType, fname, tmp);

            Debug.Print("Adding: " + fname);
        }
        /// <summary>
        /// Processes the &lt;Import&gt; element, and add an appropriate reference
        /// items to the importsItemGroup.
        /// </summary>
        /// <owner>RGoel</owner>
        private void ProcessImportElement
            (
            XmlElementWithLocation importElement,
            ProjectItemGroupElement importsItemGroup
            )
        {
            // Make sure this is the <Import> element.
            error.VerifyThrow((importElement != null) &&
                (importElement.Name == VSProjectElements.import),
                "Expected <Import> element.");

            // Make sure the caller has already created an ProjectItemGroupElement for us to
            // put the new items in.
            error.VerifyThrow(importsItemGroup != null, "Received null ProjectItemGroupElement");

            // Get the required "Namespace" attribute.
            string importNamespace = importElement.GetAttribute(VSProjectAttributes.importNamespace);
            ProjectErrorUtilities.VerifyThrowInvalidProject((importNamespace != null) && (importNamespace.Length > 0),
                importElement.Location, "MissingAttribute", VSProjectAttributes.importNamespace, VSProjectElements.import);
            // Remove the "Namespace" attribute, so it doesn't show up in our loop later.
            importElement.RemoveAttribute(VSProjectAttributes.importNamespace);

            // The <Import> element gets converted to XMake as an item of type "Import".
            // The "Namespace" attribute becomes the "Include" for the new item.  For
            // example,
            // -----------------------------------------------------------------------
            // Everett format:
            // ===============
            //    <Import Namespace = "System.Collections" />
            // -----------------------------------------------------------------------
            // XMake format:
            // =============
            //    <Import Include="System.Collections" />
            // -----------------------------------------------------------------------
            importsItemGroup.AddItem(XMakeProjectStrings.import, ProjectCollection.Escape(importNamespace));

            // There should be no other attributes on the <Import> element (besides
            // "Namespace" which we already took care of).  But loop through them
            // anyway, so we can emit a useful error message.
            foreach (XmlAttributeWithLocation importAttribute in importElement.Attributes)
            {
                ProjectErrorUtilities.VerifyThrowInvalidProject(false, importAttribute.Location, "UnrecognizedAttribute",
                    importAttribute.Name, VSProjectElements.import);
            }

            // There should be no children of the <Import> element.
            ProjectXmlUtilities.VerifyThrowProjectNoChildElements(importElement);
        }
        /// <summary>
        /// Processes the &lt;Folder&gt; element, and adds an appropriate item to the
        /// filesItemGroup.
        /// </summary>
        /// <owner>RGoel</owner>
        private void ProcessFolderElement
            (
            XmlElementWithLocation      folderElement,
            ProjectItemGroupElement filesItemGroup
            )
        {
            // Make sure this is the <Folder> element.
            error.VerifyThrow((folderElement != null) &&
                (folderElement.Name == VSProjectElements.folder),
                "Expected <Folder> element.");

            // Make sure the caller has already created an ProjectItemGroupElement for us to
            // put the new items in.
            error.VerifyThrow(filesItemGroup != null, "Received null ProjectItemGroupElement");

            // Get the required "RelPath" attribute.
            string relPath = folderElement.GetAttribute(VSProjectAttributes.relPath);
            ProjectErrorUtilities.VerifyThrowInvalidProject((relPath != null) && (relPath.Length > 0),
                folderElement.Location, "MissingAttribute", VSProjectAttributes.relPath, VSProjectElements.folder);
            // Remove the "RelPath" attribute, so we don't end up adding it twice.
            folderElement.RemoveAttribute(VSProjectAttributes.relPath);

            // We need to find out what type of folder this is -- a web references
            // folder, a web reference URL, or just an empty project folder.

            // See if there's a "WebReferences" attribute on the <Folder> element.  If so,
            // and the value is set to "True", then it's a web reference folder.
            string webReferences = folderElement.GetAttribute(VSProjectAttributes.webReferences);
            // Remove the "WebReferences" attribute, so we don't end up adding it twice.
            folderElement.RemoveAttribute(VSProjectAttributes.webReferences);

            // See if there's a "WebReferenceURL" attribute.  If so, it's a web reference
            // URL.
            string webReferenceUrl = folderElement.GetAttribute(VSProjectAttributes.webReferenceUrl);
            // Remove the "WebReferenceURL" attribute, so we don't end up adding it twice.
            folderElement.RemoveAttribute(VSProjectAttributes.webReferenceUrl);

            ProjectItemElement newFolderItem;

            if ((webReferences != null) && (0 == String.Compare(webReferences, "true", StringComparison.OrdinalIgnoreCase)))
            {
                // This is a web reference folder.

                // The <Folder> element gets converted to XMake as an item of type
                // "WebReferences".  The "Include" will contain the relative path.
                // For example,
                // -----------------------------------------------------------------------
                // Everett format:
                // ===============
                //    <Folder
                //        RelPath = "Web References\"
                //        WebReferences = "TRUE"
                //    />
                // -----------------------------------------------------------------------
                // XMake format:
                // =============
                //    <WebReferences Include = "Web References\" />
                // -----------------------------------------------------------------------
                newFolderItem = filesItemGroup.AddItem(XMakeProjectStrings.webReferences,
                    ProjectCollection.Escape(relPath));
            }
            else if ((webReferenceUrl != null) && (webReferenceUrl.Length > 0))
            {
                // This is an actual web reference URL.

                // The <Folder> element gets converted to XMake as an item of type
                // "WebReferenceURL".  The "Include" will contain the URL.
                // For example,
                // -----------------------------------------------------------------------
                // Everett format:
                // ===============
                //    <Folder
                //        RelPath = "Web References\mobileakipman\"
                //        WebReferenceUrl = "http://mobileakipman/HelloName/service1.asmx"
                //        UrlBehavior = "Static"
                //    />
                // -----------------------------------------------------------------------
                // XMake format:
                // =============
                //    <WebReferenceUrl Include="http://mobileakipman/HelloName/service1.asmx">
                //          <RelPath>Web References\mobileakipman\</RelPath>
                //          <UrlBehavior>Static</UrlBehavior>
                //    </WebReferenceUrl>
                // -----------------------------------------------------------------------
                newFolderItem = filesItemGroup.AddItem(XMakeProjectStrings.webReferenceUrl,
                    ProjectCollection.Escape(webReferenceUrl));
                newFolderItem.AddMetadata(XMakeProjectStrings.relPath, ProjectCollection.Escape(relPath));

                // Whidbey projects have some new properties to control the behavior of the
                // proxy generation.  For projects migrated from Everett, we want to force
                // the proxy generation to mimic the Everett behavior, so that people's projects
                // still work the same as they did in Everett.  (These properties did not
                // exist in Everett.)  See spec at:
                // http://devdiv/SpecTool/Documents/Whidbey/VSCore/Solution%20Project%20Build/FeatureSpecs/Project-WebReferences.doc
                if (!this.newWebReferencePropertiesAdded)
                {
                    this.globalPropertyGroup.AddProperty(XMakeProjectStrings.webRefEnableProperties,
                        (this.language == VSProjectElements.visualJSharp) ? "false" : "true");
                    this.globalPropertyGroup.AddProperty(XMakeProjectStrings.webRefEnableSqlTypes, "false");
                    this.globalPropertyGroup.AddProperty(XMakeProjectStrings.webRefEnableLegacyEventing, "true");

                    this.newWebReferencePropertiesAdded = true;
                }
            }
            else
            {
                // This is just a project folder that happens not to have any files in it.

                // The <Folder> element gets converted to XMake as an item of type "Folder".
                // However, we do need to remove the trailing backslash, because XMake
                // interprets that as a recursion (bug # 58591).  For example,
                // -----------------------------------------------------------------------
                // Everett format:
                // ===============
                //    <Folder
                //        RelPath = "MyEmptyProjectFolder\"
                //    />
                // -----------------------------------------------------------------------
                // XMake format:
                // =============
                //    <Folder Include="MyEmptyProjectFolder" />
                // -----------------------------------------------------------------------

                // Remove the trailing backslash.  XMake interprets trailing backslashes
                // as a recursive wildcard.  This will be fixed in M2 -- bug # 58591
                if (relPath.EndsWith("\\", StringComparison.Ordinal))
                {
                    relPath = relPath.Remove(relPath.Length - 1, 1);
                }

                newFolderItem = filesItemGroup.AddItem(XMakeProjectStrings.folder,
                    ProjectCollection.Escape(relPath));
            }

            // Add all the rest of the attributes on the <Folder> element to the new
            // XMake item.
            foreach (XmlAttribute folderAttribute in folderElement.Attributes)
            {
                newFolderItem.AddMetadata(folderAttribute.Name, ProjectCollection.Escape(folderAttribute.Value));
            }

            // There should be no children of the <Folder> element.
            ProjectXmlUtilities.VerifyThrowProjectNoChildElements(folderElement);
        }
Exemple #30
0
        /// <summary>
        /// Parse a ProjectItemGroupElement
        /// </summary>
        private ProjectItemGroupElement ParseProjectItemGroupElement(XmlElementWithLocation element, ProjectElementContainer parent)
        {
            ProjectXmlUtilities.VerifyThrowProjectAttributes(element, s_validAttributesOnlyConditionAndLabel);

            ProjectItemGroupElement itemGroup = new ProjectItemGroupElement(element, parent, _project);

            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                ProjectItemElement item = ParseProjectItemElement(childElement, itemGroup);

                itemGroup.AppendParentedChildNoChecks(item);
            }

            return itemGroup;
        }
Exemple #31
0
 static void generateCompile(ProjectItemGroupElement pige, string tmp2)
 {
     generateCompile(pige, tmp2, null);
 }
Exemple #32
0
        /// <summary>
        /// Parse a ProjectItemElement
        /// </summary>
        private ProjectItemElement ParseProjectItemElement(XmlElementWithLocation element, ProjectItemGroupElement parent)
        {
            bool belowTarget = parent.Parent is ProjectTargetElement;

            string itemType = element.Name;
            string include  = element.GetAttribute(XMakeAttributes.include);
            string exclude  = element.GetAttribute(XMakeAttributes.exclude);
            string remove   = element.GetAttribute(XMakeAttributes.remove);
            string update   = element.GetAttribute(XMakeAttributes.update);

            var exclusiveItemOperation  = "";
            int exclusiveAttributeCount = 0;

            if (element.HasAttribute(XMakeAttributes.include))
            {
                exclusiveAttributeCount++;
                exclusiveItemOperation = XMakeAttributes.include;
            }
            if (element.HasAttribute(XMakeAttributes.remove))
            {
                exclusiveAttributeCount++;
                exclusiveItemOperation = XMakeAttributes.remove;
            }
            if (element.HasAttribute(XMakeAttributes.update))
            {
                exclusiveAttributeCount++;
                exclusiveItemOperation = XMakeAttributes.update;
            }

            //  At most one of the include, remove, or update attributes may be specified
            if (exclusiveAttributeCount > 1)
            {
                XmlAttributeWithLocation errorAttribute = remove.Length > 0 ? (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.remove] : (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.update];
                ProjectErrorUtilities.ThrowInvalidProject(errorAttribute.Location, "InvalidAttributeExclusive");
            }

            // Include, remove, or update must be present unless inside a target
            ProjectErrorUtilities.VerifyThrowInvalidProject(exclusiveAttributeCount == 1 || belowTarget, element.Location, "IncludeRemoveOrUpdate", exclusiveItemOperation, itemType);

            // Exclude must be missing, unless Include exists
            ProjectXmlUtilities.VerifyThrowProjectInvalidAttribute(exclude.Length == 0 || include.Length > 0, (XmlAttributeWithLocation)element.Attributes[XMakeAttributes.exclude]);

            // If we have an Include attribute at all, it must have non-zero length
            ProjectErrorUtilities.VerifyThrowInvalidProject(include.Length > 0 || element.Attributes[XMakeAttributes.include] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.include, itemType);

            // If we have a Remove attribute at all, it must have non-zero length
            ProjectErrorUtilities.VerifyThrowInvalidProject(remove.Length > 0 || element.Attributes[XMakeAttributes.remove] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.remove, itemType);

            // If we have an Update attribute at all, it must have non-zero length
            ProjectErrorUtilities.VerifyThrowInvalidProject(update.Length > 0 || element.Attributes[XMakeAttributes.update] == null, element.Location, "MissingRequiredAttribute", XMakeAttributes.update, itemType);

            XmlUtilities.VerifyThrowProjectValidElementName(element);
            ProjectErrorUtilities.VerifyThrowInvalidProject(XMakeElements.IllegalItemPropertyNames[itemType] == null, element.Location, "CannotModifyReservedItem", itemType);

            ProjectItemElement item = new ProjectItemElement(element, parent, _project);

            foreach (XmlAttributeWithLocation attribute in element.Attributes)
            {
                bool isKnownAttribute;
                bool isValidMetadataNameInAttribute;

                CheckMetadataAsAttributeName(attribute.Name, out isKnownAttribute, out isValidMetadataNameInAttribute);

                if (!isKnownAttribute && !isValidMetadataNameInAttribute)
                {
                    ProjectXmlUtilities.ThrowProjectInvalidAttribute(attribute);
                }
                else if (isValidMetadataNameInAttribute)
                {
                    ProjectMetadataElement metadatum = _project.CreateMetadataElement(attribute.Name, attribute.Value);
                    metadatum.ExpressedAsAttribute = true;
                    metadatum.Parent = item;

                    item.AppendParentedChildNoChecks(metadatum);
                }
            }

            foreach (XmlElementWithLocation childElement in ProjectXmlUtilities.GetVerifyThrowProjectChildElements(element))
            {
                ProjectMetadataElement metadatum = ParseProjectMetadataElement(childElement, item);

                item.AppendParentedChildNoChecks(metadatum);
            }

            return(item);
        }
Exemple #33
0
 static void generateCompile(ProjectItemGroupElement pige, string tmp2, IDictionary<string, string> tmp)
 {
     pige.AddItem("Compile", tmp2, tmp);
     Debug.Print("Adding: " + tmp2);
 }