Ejemplo n.º 1
0
        protected override BuildResult Build(Configuration solutionConfiguration)
        {
            // explicitly set the Configuration and Platform
            MSBuildConfiguration projectConfig = (MSBuildConfiguration)BuildConfigurations[solutionConfiguration];

            _msproj.GlobalProperties.SetProperty("Configuration", projectConfig.Name);
            SetPlatform(projectConfig.PlatformName);

            // DONE: MSBuild'll resolve all references once again
            // is there any way how to disable it?
            // moreover, they could be resolved to something else!

            //We should set:
            //@(ReferencePath)
            //@(ReferenceDependencyPaths)
            //@(NativeReference)
            //@(NativeReferenceFile)
            //maybe @(WebReferenceUrl)
            //maybe @(_ReferenceRelatedPaths)
            //@(ReferenceSatellitePaths)

            // or maybe modify original references to contain full path to whatever we resolved?
            // that seems reasonable. Try it:
            _msproj.RemoveItemsByName("Reference");
            _msproj.RemoveItemsByName("ProjectReference");
            Microsoft.Build.BuildEngine.BuildItemGroup refs = _msproj.AddNewItemGroup();
            foreach (ReferenceBase r in _references)
            {
                string path = r.GetPrimaryOutputFile(solutionConfiguration);
                if (path == null || !File.Exists(path))
                {
                    continue;
                }
                Microsoft.Build.BuildEngine.BuildItem i = refs.AddNewItem("Reference", r.Name);
                i.SetMetadata("HintPath", path);
                i.SetMetadata("CopyLocal", r.CopyLocal ? "True" : "False");
            }

            // this should disable assembly resolution and always use hintpath (which we supply)
            _msproj.GlobalProperties.SetProperty("AssemblySearchPaths", "{HintPathFromItem}");

            if (_msproj.Build())
            {
                return(BuildResult.Success);
            }
            return(BuildResult.Failed);
        }
Ejemplo n.º 2
0
        public void FileProperties()
        {
            using (PackageTestEnvironment testEnv = new PackageTestEnvironment())
            {
                PropertyInfo buildProjectInfo = typeof(VisualStudio.Project.ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic);
                Microsoft.Build.BuildEngine.Project buildProject = buildProjectInfo.GetValue(testEnv.Project, new object[0]) as Microsoft.Build.BuildEngine.Project;

                // Add a node to the project map so it can be resolved
                Microsoft.Build.BuildEngine.BuildItemGroup itemGroup = buildProject.GetEvaluatedItemsByName("Compile");
                Microsoft.Build.BuildEngine.BuildItem      item      = null;
                foreach (Microsoft.Build.BuildEngine.BuildItem currentItem in itemGroup)
                {
                    if (currentItem.FinalItemSpec == "OtherFile.cs")
                    {
                        item = currentItem;
                        break;
                    }
                }
                VisualStudio.Project.FileNode node = new VisualStudio.Project.FileNode(testEnv.Project, testEnv.Project.GetProjectElement(item));
                MethodInfo itemMapGetter           = typeof(VisualStudio.Project.ProjectNode).GetProperty("ItemIdMap", BindingFlags.Instance | BindingFlags.NonPublic).GetGetMethod(true);
                Microsoft.VisualStudio.Shell.EventSinkCollection itemMap = (Microsoft.VisualStudio.Shell.EventSinkCollection)itemMapGetter.Invoke(testEnv.Project, new object[0]);
                uint itemID = itemMap.Add(node);

                IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage;
                Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage.");
                // Get
                string propertyName = "Metadata";
                string value        = null;
                int    hr           = buildProperty.GetItemAttribute(itemID, propertyName, out value);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetItemAttribute failed");
                Assert.AreEqual("OtherFileProperty", value);

                // Set (with get to confirm)
                string newValue = "UpdatedFileProperty";
                hr = buildProperty.SetItemAttribute(itemID, propertyName, newValue);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "SetPropertyValue failed");
                hr = buildProperty.GetItemAttribute(itemID, propertyName, out value);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetItemAttribute failed");
                Assert.AreEqual(newValue, value);
            }
        }
        private void SetProjectItemsThatRelyOnReferencesToBeResolved(bool renameItemNode)
        {
            // Call MSBuild to build the target ResolveComReferences
            bool success;

            ErrorHandler.ThrowOnFailure(this.ProjectMgr.BuildTarget(MsBuildTarget.ResolveComReferences, out success));
            if (!success)
            {
                throw new InvalidOperationException();
            }

            // Now loop through the generated COM References to find the corresponding one
            Microsoft.Build.BuildEngine.BuildItemGroup comReferences = this.ProjectMgr.BuildProject.GetEvaluatedItemsByName(MsBuildGeneratedItemType.ComReferenceWrappers);
            foreach (Microsoft.Build.BuildEngine.BuildItem reference in comReferences)
            {
                if (String.Compare(reference.GetMetadata(ProjectFileConstants.Guid), this.typeGuid.ToString("B"), StringComparison.OrdinalIgnoreCase) == 0 &&
                    String.Compare(reference.GetMetadata(ProjectFileConstants.VersionMajor), this.majorVersionNumber, StringComparison.OrdinalIgnoreCase) == 0 &&
                    String.Compare(reference.GetMetadata(ProjectFileConstants.VersionMinor), this.minorVersionNumber, StringComparison.OrdinalIgnoreCase) == 0 &&
                    String.Compare(reference.GetMetadata(ProjectFileConstants.Lcid), this.lcid, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    string name = reference.FinalItemSpec;
                    if (Path.IsPathRooted(name))
                    {
                        this.projectRelativeFilePath = name;
                    }
                    else
                    {
                        this.projectRelativeFilePath = Path.Combine(this.ProjectMgr.ProjectFolder, name);
                    }

                    if (renameItemNode)
                    {
                        this.ItemNode.Rename(Path.GetFileNameWithoutExtension(name));
                    }
                    break;
                }
            }
        }
Ejemplo n.º 4
0
 public void RemoveItemGroup(Microsoft.Build.BuildEngine.BuildItemGroup itemGroupToRemove)
 {
 }
Ejemplo n.º 5
0
        public MSBuildProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir)
            : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)
        {
            string cfgname  = solutionTask.Configuration;
            string platform = solutionTask.Platform;

            _msbuild             = MSBuildEngine.CreateMSEngine(solutionTask);
            _msproj              = new Microsoft.Build.BuildEngine.Project(_msbuild);
            _msproj.FullFileName = projectPath;
            _msproj.LoadXml(xmlDefinition.OuterXml);
            _msproj.GlobalProperties.SetProperty("Configuration", cfgname);
            SetPlatform(platform);
            if (outputDir != null)
            {
                _msproj.GlobalProperties.SetProperty("OutputPath", outputDir.FullName);
            }

            //evaluating
            _guid             = _msproj.GetEvaluatedProperty("ProjectGuid");
            _projectDirectory = new DirectoryInfo(_msproj.GetEvaluatedProperty("ProjectDir"));
            _projectPath      = _msproj.GetEvaluatedProperty("ProjectPath");

            ProjectEntry projectEntry = solution.ProjectEntries [_guid];

            if (projectEntry != null && projectEntry.BuildConfigurations != null)
            {
                foreach (ConfigurationMapEntry ce in projectEntry.BuildConfigurations)
                {
                    Configuration projectConfig = ce.Value;
                    ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig);
                }
            }
            else
            {
                Configuration projectConfig = new Configuration(cfgname, platform);
                ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig);
            }

            //references
            _references = new ArrayList();
            Microsoft.Build.BuildEngine.BuildItemGroup refs = _msproj.GetEvaluatedItemsByName("Reference");
            foreach (Microsoft.Build.BuildEngine.BuildItem r in refs)
            {
                string rpath    = r.FinalItemSpec;
                string priv     = r.GetMetadata("Private");
                string hintpath = r.GetMetadata("HintPath");

                ReferenceBase reference = new MSBuildAssemblyReference(
                    xmlDefinition, ReferencesResolver, this, gacCache,
                    rpath, priv, hintpath);
                _references.Add(reference);
            }
            refs = _msproj.GetEvaluatedItemsByName("ProjectReference");
            foreach (Microsoft.Build.BuildEngine.BuildItem r in refs)
            {
                string        pguid     = r.GetMetadata("Project");
                string        pname     = r.GetMetadata("Name");
                string        rpath     = r.FinalItemSpec;
                string        priv      = r.GetMetadata("Private");
                ReferenceBase reference = new MSBuildProjectReference(
                    ReferencesResolver, this, solution, tfc, gacCache, outputDir,
                    pguid, pname, rpath, priv);
                _references.Add(reference);
            }
        }