Пример #1
0
        public void ResolveBinary_FancyStuffAndXbuild()
        {
            engine  = new Engine(Consts.BinPath);
            project = engine.CreateNewProject();
            project.LoadXml(ResolveAssembly(null, @"Test\resources\binary\FancyStuff.dll", @"Test\resources\binary\XbuildReferenceBugTest.exe"));

            Assert.IsTrue(project.Build("A"), "A1");
            big = project.GetEvaluatedItemsByName("ResolvedFiles");
            Assert.AreEqual(2, big.Count, "A2");
            Assert.IsTrue(big[0].Include.EndsWith("FancyStuff.dll"), "A3");
            Assert.IsTrue(big[1].Include.EndsWith("XbuildReferenceBugTest.exe"), "A3");

            big = project.GetEvaluatedItemsByName("ResolvedDependencyFiles");
            Assert.AreEqual(2, big.Count, "A4");
            Assert.IsTrue(big.Cast <BuildItem> ().Any(item => item.Include.EndsWith("SimpleWrite.dll")), "A5");
            Assert.IsTrue(big.Cast <BuildItem> ().Any(item => item.Include.EndsWith("Testing.dll")), "A6");
        }
Пример #2
0
        public void ResolveBinary_FancyStuff()
        {
            engine  = new Engine(Consts.BinPath);
            project = engine.CreateNewProject();
            project.LoadXml(ResolveAssembly(null, TestResourceHelper.GetFullPathOfResource("Test/resources/binary/FancyStuff.dll")));

            Assert.IsTrue(project.Build("A"), "A1");
            big = project.GetEvaluatedItemsByName("ResolvedFiles");
            Assert.AreEqual(1, big.Count, "A2");
            Assert.IsTrue(big[0].Include.EndsWith("FancyStuff.dll"), "A3");

            big = project.GetEvaluatedItemsByName("ResolvedDependencyFiles");
            Assert.AreEqual(1, big.Count, "A4");
            Assert.IsTrue(big.Cast <BuildItem> ().Any(item => item.Include.EndsWith("SimpleWrite.dll")), "A5");
        }
Пример #3
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        public override bool Execute()
        {
            foreach (ITaskItem taskItem in this.Projects)
            {
                switch (GetClassification(taskItem))
                {
                case ProjectClassification.VS2010Project:
                    this.Log.LogMessage(MessageImportance.Low, "Downgrading project \"{0}\".", taskItem.ItemSpec);
                    Project project = new Project();
                    project.Load(taskItem.ItemSpec);
                    project.DefaultToolsVersion = "3.5";

                    if (this.DowngradeMvc2ToMvc1)
                    {
                        string projectTypeGuids = project.GetEvaluatedProperty("ProjectTypeGuids");
                        if (!string.IsNullOrEmpty(projectTypeGuids))
                        {
                            projectTypeGuids = projectTypeGuids.Replace("{F85E285D-A4E0-4152-9332-AB1D724D3325}", "{603c0e0b-db56-11dc-be95-000d561079b0}");
                            project.SetProperty("ProjectTypeGuids", projectTypeGuids);
                        }
                    }

                    // Web projects usually have an import that includes these substrings
                    foreach (Import import in project.Imports)
                    {
                        import.ProjectPath = import.ProjectPath
                                             .Replace("$(MSBuildExtensionsPath32)", "$(MSBuildExtensionsPath)")
                                             .Replace("VisualStudio\\v10.0", "VisualStudio\\v9.0");
                    }

                    // VS2010 won't let you have a System.Core reference, but VS2008 requires it.
                    BuildItemGroup references = project.GetEvaluatedItemsByName("Reference");
                    if (!references.Cast <BuildItem>().Any(item => item.FinalItemSpec.StartsWith("System.Core", StringComparison.OrdinalIgnoreCase)))
                    {
                        project.AddNewItem("Reference", "System.Core");
                    }

                    project.Save(taskItem.ItemSpec);
                    break;

                case ProjectClassification.VS2010Solution:
                    this.Log.LogMessage(MessageImportance.Low, "Downgrading solution \"{0}\".", taskItem.ItemSpec);
                    string[] contents = File.ReadAllLines(taskItem.ItemSpec);
                    if (contents[1] != "Microsoft Visual Studio Solution File, Format Version 11.00" ||
                        contents[2] != "# Visual Studio 2010")
                    {
                        this.Log.LogError("Unrecognized solution file header in \"{0}\".", taskItem.ItemSpec);
                        break;
                    }

                    contents[1] = "Microsoft Visual Studio Solution File, Format Version 10.00";
                    contents[2] = "# Visual Studio 2008";

                    for (int i = 3; i < contents.Length; i++)
                    {
                        contents[i] = contents[i].Replace("TargetFrameworkMoniker = \".NETFramework,Version%3Dv", "TargetFramework = \"");
                    }

                    File.WriteAllLines(taskItem.ItemSpec, contents);
                    break;

                default:
                    this.Log.LogWarning("Unrecognized project type for \"{0}\".", taskItem.ItemSpec);
                    break;
                }
            }

            return(!this.Log.HasLoggedErrors);
        }
Пример #4
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        public override bool Execute()
        {
            var newProjectToOldProjectMapping = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            var createdProjectFiles           = new List <TaskItem>();

            foreach (ITaskItem taskItem in this.Projects)
            {
                switch (GetClassification(taskItem))
                {
                case ProjectClassification.VS2010Project:
                case ProjectClassification.VS2010Solution:
                    string projectNameForVS2008 = InPlaceDowngrade
                                                                                                                ? taskItem.ItemSpec
                                                                                                                : Path.Combine(
                        Path.GetDirectoryName(taskItem.ItemSpec),
                        Path.GetFileNameWithoutExtension(taskItem.ItemSpec) + "-vs2008" +
                        Path.GetExtension(taskItem.ItemSpec));
                    newProjectToOldProjectMapping[taskItem.ItemSpec] = projectNameForVS2008;
                    break;
                }
            }

            foreach (ITaskItem taskItem in this.Projects)
            {
                switch (GetClassification(taskItem))
                {
                case ProjectClassification.VS2010Project:
                    this.Log.LogMessage(MessageImportance.Low, "Downgrading project \"{0}\".", taskItem.ItemSpec);
                    var project = new Project();
                    project.Load(taskItem.ItemSpec, ProjectLoadSettings.IgnoreMissingImports);
                    project.DefaultToolsVersion = "3.5";

                    if (this.DowngradeMvc2ToMvc1)
                    {
                        string projectTypeGuids = project.GetEvaluatedProperty("ProjectTypeGuids");
                        if (!string.IsNullOrEmpty(projectTypeGuids))
                        {
                            projectTypeGuids = projectTypeGuids.Replace("{F85E285D-A4E0-4152-9332-AB1D724D3325}", "{603c0e0b-db56-11dc-be95-000d561079b0}");
                            project.SetProperty("ProjectTypeGuids", projectTypeGuids);
                        }
                    }

                    // MSBuild v3.5 doesn't support the GetDirectoryNameOfFileAbove function
                    var enlistmentInfoImports = project.Imports.Cast <Import>().Where(i => i.ProjectPath.IndexOf("[MSBuild]::GetDirectoryNameOfFileAbove", StringComparison.OrdinalIgnoreCase) >= 0);
                    enlistmentInfoImports.ToList().ForEach(i => project.Imports.RemoveImport(i));

                    // Web projects usually have an import that includes these substrings));)
                    foreach (Import import in project.Imports)
                    {
                        import.ProjectPath = import.ProjectPath
                                             .Replace("$(MSBuildExtensionsPath32)", "$(MSBuildExtensionsPath)")
                                             .Replace("VisualStudio\\v10.0", "VisualStudio\\v9.0");
                    }

                    // VS2010 won't let you have a System.Core reference, but VS2008 requires it.
                    BuildItemGroup references = project.GetEvaluatedItemsByName("Reference");
                    if (!references.Cast <BuildItem>().Any(item => item.FinalItemSpec.StartsWith("System.Core", StringComparison.OrdinalIgnoreCase)))
                    {
                        project.AddNewItem("Reference", "System.Core");
                    }

                    // Rewrite ProjectReferences to other renamed projects.
                    BuildItemGroup projectReferences = project.GetEvaluatedItemsByName("ProjectReference");
                    foreach (var mapping in newProjectToOldProjectMapping)
                    {
                        string oldName = Path.GetFileName(mapping.Key);
                        string newName = Path.GetFileName(mapping.Value);
                        foreach (BuildItem projectReference in projectReferences)
                        {
                            projectReference.Include = Regex.Replace(projectReference.Include, oldName, newName, RegexOptions.IgnoreCase);
                        }
                    }

                    project.Save(newProjectToOldProjectMapping[taskItem.ItemSpec]);
                    createdProjectFiles.Add(new TaskItem(taskItem)
                    {
                        ItemSpec = newProjectToOldProjectMapping[taskItem.ItemSpec]
                    });
                    break;

                case ProjectClassification.VS2010Solution:
                    this.Log.LogMessage(MessageImportance.Low, "Downgrading solution \"{0}\".", taskItem.ItemSpec);
                    string[] contents = File.ReadAllLines(taskItem.ItemSpec);
                    if (contents[1] != "Microsoft Visual Studio Solution File, Format Version 11.00" ||
                        contents[2] != "# Visual Studio 2010")
                    {
                        this.Log.LogError("Unrecognized solution file header in \"{0}\".", taskItem.ItemSpec);
                        break;
                    }

                    contents[1] = "Microsoft Visual Studio Solution File, Format Version 10.00";
                    contents[2] = "# Visual Studio 2008";

                    for (int i = 3; i < contents.Length; i++)
                    {
                        contents[i] = contents[i].Replace("TargetFrameworkMoniker = \".NETFramework,Version%3Dv", "TargetFramework = \"");
                    }

                    foreach (var mapping in newProjectToOldProjectMapping)
                    {
                        string oldName = Path.GetFileName(mapping.Key);
                        string newName = Path.GetFileName(mapping.Value);
                        for (int i = 0; i < contents.Length; i++)
                        {
                            contents[i] = Regex.Replace(contents[i], oldName, newName, RegexOptions.IgnoreCase);
                        }
                    }

                    File.WriteAllLines(newProjectToOldProjectMapping[taskItem.ItemSpec], contents);
                    createdProjectFiles.Add(new TaskItem(taskItem)
                    {
                        ItemSpec = newProjectToOldProjectMapping[taskItem.ItemSpec]
                    });
                    break;

                default:
                    this.Log.LogWarning("Unrecognized project type for \"{0}\".", taskItem.ItemSpec);
                    break;
                }
            }

            if (InPlaceDowngrade)
            {
                this.DowngradedProjects = new ITaskItem[0];
            }
            else
            {
                this.DowngradedProjects = createdProjectFiles.ToArray();
            }

            return(!this.Log.HasLoggedErrors);
        }