예제 #1
0
        // ==========================================================================================

        /// <summary>
        /// Extract input and output properties from MSBuild.
        /// </summary>
        private void GatherNativeInputsAndOutputs()
        {
            m_extension = this.GetPropertyValue("TargetExt");
            //Debug.Assert(String.IsNullOrEmpty(m_extension) == false);
            m_output_binary = (this.GetPropertyValue("TargetName") + m_extension).ToLower();
            //Debug.Assert(String.IsNullOrEmpty(m_extension) == false);
            m_output_binary_path = this.GetPropertyValue("TargetPath");

            ProjectItemDefinition LinkDef = null;

            if (String.Compare(".lib", m_extension, true) == 0)
            {
                LinkDef = this.ItemDefinitions["Lib"];
            }
            else
            {
                LinkDef = this.ItemDefinitions["Link"];
            }

            //Debug.Assert(LinkDef != null);
            if (LinkDef != null)
            {
                String importLibPath = LinkDef.GetMetadataValue("ImportLibrary");
                //Debug.Assert(importLibPath != null);
                if (String.IsNullOrEmpty(importLibPath) == false)
                {
                    m_Import_Library_FullPath = importLibPath.ToLower();
                }
                m_import_library = Path.GetFileName(importLibPath).ToLower();
                if (String.Compare(".lib", m_extension, true) == 0)
                {
                    m_import_library = m_output_binary;
                }

                String additionalDependencies = LinkDef.GetMetadataValue("AdditionalDependencies");
                //Debug.Assert(additionalDependencies != null);
                ResolveInputLibraries(additionalDependencies);

                String PDB = LinkDef.GetMetadataValue("ProgramDatabaseFile");
                //Debug.Assert(PDB != null);
                m_pdb_filename = Path.GetFileName(PDB).ToLower();
            }

            ProjectItemDefinition MidlDef = this.ItemDefinitions["Midl"];

            if (MidlDef != null)
            {
                ProjectMetadata metaTypeLibraryName = MidlDef.GetMetadata("TypeLibraryName");
                if (metaTypeLibraryName.IsImported == false)
                {
                    String typeLibrary = metaTypeLibraryName.EvaluatedValue;
                    String tname       = Path.GetFileName(this.ExpandString(typeLibrary)).ToLower();
                    m_typelibrary = tname;
                }
            }
        }
예제 #2
0
        // public static void Verify(ProjectItemDefinition view, ProjectItemDefinition real) => Verify(view, real, null);
        public static void Verify(ProjectItemDefinition view, ProjectItemDefinition real, ValidationContext context)
        {
            if (view == null && real == null)
            {
                return;
            }
            VerifyLinkedNotNull(view);
            VerifyNotLinkedNotNull(real);

            // note ItemDefinition does not have a XML element
            // this is since it is [or can be] a aggregation of multiple ProjectItemDefinitionElement's.
            // This is somewhat of deficiency of MSBuild API.
            // (for example SetMetadata will always create a new ItemDefinitionElement because of that, for new metadata).

            Assert.Equal(real.ItemType, view.ItemType);
            Assert.Equal(real.MetadataCount, view.MetadataCount);

            Verify(view.Metadata, real.Metadata, Verify, context);

            foreach (var rm in real.Metadata)
            {
                var rv = real.GetMetadataValue(rm.Name);
                var vv = view.GetMetadataValue(rm.Name);
                Assert.Equal(rv, vv);

                var grm = real.GetMetadata(rm.Name);
                var gvm = view.GetMetadata(rm.Name);

                Verify(gvm, grm, context);
            }

            VerifyLinkedNotNull(view.Project);
            VerifyNotLinkedNotNull(real.Project);
            if (context?.Pair != null)
            {
                Assert.Same(context?.Pair.View, view.Project);
                Assert.Same(context?.Pair.Real, real.Project);
            }
        }
        public void MigrateProjectReferences()
        {
            List <ProjectItem> allProjReferences = new List <ProjectItem>();

            foreach (ProjectItem i in project_.GetItemsIgnoringCondition("ProjectReference"))
            {
                allProjReferences.Add(i);
                string refProj = i.GetMetadataValue("FullPath");
                if (string.IsNullOrWhiteSpace(refProj) || !File.Exists(refProj))
                {
                    logger_.LogWarning($"File not found for project reference {i.UnevaluatedInclude}");
                    continue;
                }

                // Resolve project to package alias
                string    alias       = Path.GetFileNameWithoutExtension(refProj);
                ITaskItem refProjItem = allProjects_.FirstOrDefault((ii) => refProj.Equals(ii.GetMetadata("FullPath")));
                if (refProjItem != null)
                {
                    alias = PackagesConfig.GetProjectId(refProjItem);
                }

                logger_.LogMessage($"Project {projectItem_.ItemSpec}- Converting library reference '{refProj}' to Nuget package '{PackageIdPrefix + alias}' version {packageVersion_}");
                packagesConfig_.Add(PackageIdPrefix + alias, packageVersion_);
            }

            foreach (ProjectItem i in project_.GetItemsIgnoringCondition("Link"))
            {
                string   libDependencies = i.GetMetadataValue("AdditionalDependencies");
                string[] libs            = libDependencies.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string l in libs)
                {
                    string li = Path.GetFileNameWithoutExtension(l);
                    ConvertLibToPkg(li);
                }
            }

            foreach (ProjectMetadata i in project_.AllEvaluatedItemDefinitionMetadata)
            {
                if (i.ItemType.Equals("Link") && i.Name.Equals("AdditionalDependencies"))
                {
                    string   libDependencies = i.EvaluatedValue;
                    string[] libs            = libDependencies.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string l in libs)
                    {
                        string li = Path.GetFileNameWithoutExtension(l);
                        ConvertLibToPkg(li);
                    }
                }
            }

            ProjectItemDefinition pid = project_.ItemDefinitions["Link"];

            if (pid != null)
            {
                string   libDependencies = pid.GetMetadataValue("AdditionalDependencies");
                string[] libs            = libDependencies.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string l in libs)
                {
                    string li = Path.GetFileNameWithoutExtension(l);
                    ConvertLibToPkg(li);
                }
            }

            project_.RemoveItems(allProjReferences);
            packagesConfig_.Save();
            project_.Save();
        }