private static void AddCustomOutputs(ISet <string> outputs, ProjectInstance projectInstance)
        {
            foreach (ProjectItemInstance customOutput in projectInstance.GetItems("UpToDateCheckOutput"))
            {
                outputs.Add(customOutput.GetMetadataValue("FullPath"));
            }

            foreach (ProjectItemInstance buildOutput in projectInstance.GetItems("UpToDateCheckBuilt").Where(i => string.IsNullOrEmpty(i.GetMetadataValue("Original"))))
            {
                outputs.Add(buildOutput.GetMetadataValue("FullPath"));
            }

            // See if this is a NoTarget SDK project. If so, skip the outputs.
            string usingNoTargets     = projectInstance.GetPropertyValue("UsingMicrosoftNoTargetsSdk");
            bool   isNoTargetsProject = !string.IsNullOrEmpty(usingNoTargets) && usingNoTargets.Trim().Equals("true", StringComparison.OrdinalIgnoreCase);

            if (!isNoTargetsProject)
            {
                return;
            }

            // This IS a NoTarget SDK project, so we have to do some further adjusting. Because of:
            // Target "CollectUpToDateCheckBuiltDesignTime" in file "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Microsoft\VisualStudio\Managed\Microsoft.Managed.DesignTime.targets"
            RemoveNoTargetsOutputs(outputs, projectInstance);
        }
Ejemplo n.º 2
0
        private static ProjectData CreateProjectData(ProjectInstance projectInstance, ImmutableArray <string> targetFrameworks)
        {
            var guid              = PropertyConverter.ToGuid(projectInstance.GetPropertyValue(PropertyNames.ProjectGuid));
            var name              = projectInstance.GetPropertyValue(PropertyNames.ProjectName);
            var assemblyName      = projectInstance.GetPropertyValue(PropertyNames.AssemblyName);
            var targetPath        = projectInstance.GetPropertyValue(PropertyNames.TargetPath);
            var outputPath        = projectInstance.GetPropertyValue(PropertyNames.OutputPath);
            var projectAssetsFile = projectInstance.GetPropertyValue(PropertyNames.ProjectAssetsFile);

            var targetFramework = new FrameworkName(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworkMoniker));

            var languageVersion           = PropertyConverter.ToLanguageVersion(projectInstance.GetPropertyValue(PropertyNames.LangVersion));
            var allowUnsafeCode           = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.AllowUnsafeBlocks), defaultValue: false);
            var outputKind                = PropertyConverter.ToOutputKind(projectInstance.GetPropertyValue(PropertyNames.OutputType));
            var documentationFile         = projectInstance.GetPropertyValue(PropertyNames.DocumentationFile);
            var preprocessorSymbolNames   = PropertyConverter.ToPreprocessorSymbolNames(projectInstance.GetPropertyValue(PropertyNames.DefineConstants));
            var suppressDiagnosticIds     = PropertyConverter.ToSuppressDiagnosticIds(projectInstance.GetPropertyValue(PropertyNames.NoWarn));
            var signAssembly              = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.SignAssembly), defaultValue: false);
            var assemblyOriginatorKeyFile = projectInstance.GetPropertyValue(PropertyNames.AssemblyOriginatorKeyFile);

            var sourceFiles       = GetFullPaths(projectInstance.GetItems(ItemNames.Compile));
            var projectReferences = GetFullPaths(projectInstance.GetItems(ItemNames.ProjectReference));
            var references        = GetFullPaths(
                projectInstance.GetItems(ItemNames.ReferencePath).Where(ReferenceSourceTargetIsNotProjectReference));
            var packageReferences = GetPackageReferences(projectInstance.GetItems(ItemNames.PackageReference));
            var analyzers         = GetFullPaths(projectInstance.GetItems(ItemNames.Analyzer));

            return(new ProjectData(guid, name,
                                   assemblyName, targetPath, outputPath, projectAssetsFile,
                                   targetFramework, targetFrameworks,
                                   outputKind, languageVersion, allowUnsafeCode, documentationFile, preprocessorSymbolNames, suppressDiagnosticIds,
                                   signAssembly, assemblyOriginatorKeyFile,
                                   sourceFiles, projectReferences, references, packageReferences, analyzers));
        }
        /// <inheritdoc/>
        public void PredictInputsAndOutputs(
            ProjectInstance projectInstance,
            ProjectPredictionReporter predictionReporter)
        {
            // This predictor only applies to sqlproj files
            if (!projectInstance.FullPath.EndsWith(".sqlproj", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            foreach (ProjectItemInstance item in projectInstance.GetItems(BuildItemName))
            {
                predictionReporter.ReportInputFile(item.EvaluatedInclude);
            }

            foreach (ProjectItemInstance item in projectInstance.GetItems(PostDeployItemName))
            {
                predictionReporter.ReportInputFile(item.EvaluatedInclude);
            }

            foreach (ProjectItemInstance item in projectInstance.GetItems(PreDeployItemName))
            {
                predictionReporter.ReportInputFile(item.EvaluatedInclude);
            }
        }
Ejemplo n.º 4
0
        public void ExpandPropertyThenTrim()
        {
            string test        = @"A
B
C
    ";
            string project_xml = string.Format(@"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <PropertyGroup>
    <Test>{0}</Test>
    <Test2>$(TEST)</Test2>
  </PropertyGroup>
  <ItemGroup>
    <X Include='$(TEST)' />
    <X2 Include='$(TEST)z' />
  </ItemGroup>
</Project>", test);
            var    xml         = XmlReader.Create(new StringReader(project_xml));
            var    root        = ProjectRootElement.Create(xml);

            root.FullPath = "ProjectItemTest.ExpandPropertyThenTrim.proj";
            var proj = new ProjectInstance(root);

            Assert.AreEqual(test, proj.GetPropertyValue("TEST"), "#1");
            Assert.AreEqual(test, proj.GetPropertyValue("TEST2"), "#2");
            Assert.AreEqual(test.Trim(), proj.GetItems("X").First().EvaluatedInclude, "#3");
            Assert.AreEqual(test + "z", proj.GetItems("X2").First().EvaluatedInclude, "#4");
        }
Ejemplo n.º 5
0
        public IEnumerable <ReferenceInfo> GetReferences(ProjectInstance requesterInstance)
        {
            IEnumerable <ProjectItemInstance>      projectReferenceItems;
            IEnumerable <GlobalPropertiesModifier> globalPropertiesModifiers = null;

            switch (GetProjectType(requesterInstance))
            {
            case ProjectType.OuterBuild:
                projectReferenceItems = ConstructInnerBuildReferences(requesterInstance);
                break;

            case ProjectType.InnerBuild:
                globalPropertiesModifiers = ModifierForNonMultitargetingNodes.Add((parts, reference) => parts.AddPropertyToUndefine(GetInnerBuildPropertyName(requesterInstance)));
                projectReferenceItems     = requesterInstance.GetItems(ItemTypeNames.ProjectReference);
                break;

            case ProjectType.NonMultitargeting:
                globalPropertiesModifiers = ModifierForNonMultitargetingNodes;
                projectReferenceItems     = requesterInstance.GetItems(ItemTypeNames.ProjectReference);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            foreach (var projectReferenceItem in projectReferenceItems)
            {
                if (!String.IsNullOrEmpty(projectReferenceItem.GetMetadataValue(ToolsVersionMetadataName)))
                {
                    throw new InvalidOperationException(
                              String.Format(
                                  CultureInfo.InvariantCulture,
                                  ResourceUtilities.GetResourceString(
                                      "ProjectGraphDoesNotSupportProjectReferenceWithToolset"),
                                  projectReferenceItem.EvaluatedInclude,
                                  requesterInstance.FullPath));
                }

                var projectReferenceFullPath = projectReferenceItem.GetMetadataValue(FullPathMetadataName);

                var referenceGlobalProperties = GetGlobalPropertiesForItem(projectReferenceItem, requesterInstance.GlobalPropertiesDictionary, globalPropertiesModifiers);

                var requesterPlatform            = "";
                var requesterPlatformLookupTable = "";

                if (ConversionUtilities.ValidBooleanTrue(requesterInstance.GetPropertyValue("EnableDynamicPlatformResolution")))
                {
                    requesterPlatform            = requesterInstance.GetPropertyValue("Platform");
                    requesterPlatformLookupTable = requesterInstance.GetPropertyValue("PlatformLookupTable");
                }

                var referenceConfig = new ConfigurationMetadata(projectReferenceFullPath, referenceGlobalProperties, requesterPlatform, requesterPlatformLookupTable, projectReferenceItem.HasMetadata("SetPlatform"));

                yield return(new ReferenceInfo(referenceConfig, projectReferenceItem));
            }
        }
Ejemplo n.º 6
0
        public void CloneItems()
        {
            ProjectInstance first  = GetSampleProjectInstance();
            ProjectInstance second = first.DeepCopy();

            Assert.False(Object.ReferenceEquals(Helpers.MakeList(first.GetItems("i"))[0], Helpers.MakeList(second.GetItems("i"))[0]));

            first.AddItem("i", "i3");
            Assert.Equal(4, Helpers.MakeList(first.GetItems("i")).Count);
            Assert.Equal(3, Helpers.MakeList(second.GetItems("i")).Count);
        }
Ejemplo n.º 7
0
            private static string[] GetCandidateAssemblyFiles(ProjectInstance projectInstance)
            {
                var candidateAssemblyFilesList = new List <ProjectItemInstance>();

                candidateAssemblyFilesList.AddRange(projectInstance.GetItems(Content));
                candidateAssemblyFilesList.AddRange(projectInstance.GetItems(None));
                candidateAssemblyFilesList.AddRange(projectInstance.GetItems(RARResolvedReferencePath));

                string[] candidateAssemblyFiles = candidateAssemblyFilesList.Select((Func <ProjectItemInstance, string>)((item) => { return(item.GetMetadataValue("FullPath").Trim()); })).ToArray();

                return(candidateAssemblyFiles);
            }
        /// <inheritdoc/>
        public void PredictInputsAndOutputs(ProjectInstance projectInstance, ProjectPredictionReporter predictionReporter)
        {
            // This predictor only applies to projects using the Microsoft.Build.Artifacts Sdk.
            var usingMicrosoftArtifactsSdk = projectInstance.GetPropertyValue(UsingMicrosoftArtifactsSdkPropertyName);

            if (!usingMicrosoftArtifactsSdk.Equals("true", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // The Sdk allows both Artifacts and Robocopy items
            ProcessItems(projectInstance.GetItems(ArtifactsItemName), predictionReporter);
            ProcessItems(projectInstance.GetItems(RobocopyItemName), predictionReporter);
        }
Ejemplo n.º 9
0
            public static TargetsToPropagate FromProjectAndEntryTargets(ProjectInstance project, ImmutableList <string> entryTargets)
            {
                var targetsForOuterBuild = ImmutableList.CreateBuilder <string>();
                var targetsForInnerBuild = ImmutableList.CreateBuilder <string>();

                var projectReferenceTargets = project.GetItems(ItemTypeNames.ProjectReferenceTargets);

                foreach (var entryTarget in entryTargets)
                {
                    foreach (var projectReferenceTarget in projectReferenceTargets)
                    {
                        if (projectReferenceTarget.EvaluatedInclude.Equals(entryTarget, StringComparison.OrdinalIgnoreCase))
                        {
                            var targetsMetadataValue = projectReferenceTarget.GetMetadataValue(ItemMetadataNames.ProjectReferenceTargetsMetadataName);

                            var targetsAreForOuterBuild = projectReferenceTarget.GetMetadataValue(ProjectReferenceTargetIsOuterBuildMetadataName).Equals("true", StringComparison.OrdinalIgnoreCase);

                            var targets = ExpressionShredder.SplitSemiColonSeparatedList(targetsMetadataValue).ToArray();

                            if (targetsAreForOuterBuild)
                            {
                                targetsForOuterBuild.AddRange(targets);
                            }
                            else
                            {
                                targetsForInnerBuild.AddRange(targets);
                            }
                        }
                    }
                }

                return(new TargetsToPropagate(targetsForOuterBuild.ToImmutable(), targetsForInnerBuild.ToImmutable()));
            }
        /// <inheritdoc/>
        public void PredictInputsAndOutputs(
            ProjectInstance projectInstance,
            ProjectPredictionReporter predictionReporter)
        {
            var availableItemNames = new HashSet <string>(
                projectInstance.GetItems(AvailableItemName).Select(item => item.EvaluatedInclude),
                StringComparer.OrdinalIgnoreCase);

            foreach (string availableItemName in availableItemNames)
            {
                foreach (ProjectItemInstance item in projectInstance.GetItems(availableItemName))
                {
                    predictionReporter.ReportInputFile(item.EvaluatedInclude);
                }
            }
        }
        private static void ReportCopyToPublishDirectoryItems(
            ProjectInstance projectInstance,
            string itemName,
            string publishDir,
            ProjectPredictionReporter predictionReporter)
        {
            foreach (ProjectItemInstance item in projectInstance.GetItems(itemName))
            {
                var copyToPublishDirectoryValue = item.GetMetadataValue(CopyToPublishDirectoryMetadataName);
                if (copyToPublishDirectoryValue.Equals("Always", StringComparison.OrdinalIgnoreCase) ||
                    copyToPublishDirectoryValue.Equals("PreserveNewest", StringComparison.OrdinalIgnoreCase))
                {
                    // The item will be relative to the project instance passed in, not the current project instance, so make the path absolute.
                    predictionReporter.ReportInputFile(Path.Combine(projectInstance.Directory, item.EvaluatedInclude));

                    if (!string.IsNullOrEmpty(publishDir))
                    {
                        string targetPath = item.GetTargetPath();
                        if (!string.IsNullOrEmpty(targetPath))
                        {
                            predictionReporter.ReportOutputFile(Path.Combine(publishDir, targetPath));
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private void ReportInputsForItemType(ProjectPredictionReporter reporter, ProjectInstance projectInstance, string itemType, HashSet <string> reportedIncludes)
        {
            ICollection <ProjectItemInstance> items = projectInstance.GetItems(itemType);

            if (items.Count == 0)
            {
                return;
            }

            foreach (ProjectItemInstance item in items)
            {
                if (item.GetMetadataValue(ExcludedFromBuildMetadata).Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                string[] additionalIncludeDirectories = item.GetMetadataValue(AdditionalIncludeDirectoriesMetadata)
                                                        .Split(IncludePathsSeparator, StringSplitOptions.RemoveEmptyEntries);
                foreach (string directory in additionalIncludeDirectories)
                {
                    string trimmedDirectory = directory.Trim();
                    if (!string.IsNullOrEmpty(trimmedDirectory) && reportedIncludes.Add(trimmedDirectory))
                    {
                        reporter.ReportInputDirectory(trimmedDirectory);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        /// <inheritdoc />
        public void PredictInputsAndOutputs(ProjectInstance project, ProjectPredictionReporter reporter)
        {
            // This is based on $(VCTargetsPath)\BuildCustomizations\masm.targets, if the before targets
            // property isn't set then the masm.targets haven't been imported, and no @(MASM) items will
            // be processed by the MASM targets.
            if (string.IsNullOrWhiteSpace(project.GetPropertyValue(MasmBeforeTargetsPropertyName)))
            {
                return;
            }

            ICollection <ProjectItemInstance> masmItems = project.GetItems(MasmItemName);

            if (masmItems.Count == 0)
            {
                return;
            }

            var reportedIncludes = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (ProjectItemInstance masmItem in masmItems)
            {
                if (IsExcludedFromBuild(masmItem))
                {
                    continue;
                }

                ReportInputs(reporter, masmItem, reportedIncludes);
                ReportOutputs(reporter, masmItem);
            }
        }
Ejemplo n.º 14
0
        [Category("NotWorking")]          // until we figure out why it fails on wrench.
        public void ItemsInTargets()
        {
            string project_xml = @"<Project DefaultTargets='Default' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
	<Target Name='Default'>
		<PropertyGroup>
			<_ExplicitMSCorlibPath>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries ('$(TargetFrameworkIdentifier)', '$(TargetFrameworkVersion)', '$(TargetFrameworkProfile)'))\mscorlib.dll</_ExplicitMSCorlibPath>
		</PropertyGroup>
		<ItemGroup>
			<_ExplicitReference
				Include='$(_ExplicitMSCorlibPath)'
				Condition='Exists($(_ExplicitMSCorlibPath))'>
				<Private>false</Private>
			</_ExplicitReference>
		</ItemGroup>
	</Target>
	<Import Project='$(MSBuildBinPath)\\Microsoft.CSharp.targets' />
</Project>";
            var    xml         = XmlReader.Create(new StringReader(project_xml));
            var    root        = ProjectRootElement.Create(xml);

            root.FullPath = "ProjectInstanceTest.ConditionalExpression.proj";
            var proj = new ProjectInstance(root, null, "4.0", ProjectCollection.GlobalProjectCollection);

            proj.Build();
            // make sure the property value expansion is done successfully.
            Assert.IsTrue(!string.IsNullOrEmpty(proj.GetPropertyValue("_ExplicitMSCorlibPath")), "premise: propertyValue by ToolLocationHelper func call");
            var items = proj.GetItems("_ExplicitReference");

            // make sure items are stored after build.
            Assert.IsTrue(items.Any(), "items.Any");
            Assert.IsTrue(!string.IsNullOrEmpty(items.First().EvaluatedInclude), "item.EvaluatedInclude");
        }
Ejemplo n.º 15
0
        public void TestGetItemsToDownload()
        {
            var itemUrl = "http://search.maven.org/remotecontent?filepath=com/facebook/android/facebook-android-sdk/4.17.0/facebook-android-sdk-4.17.0.aar";

            var engine = new ProjectCollection();
            var prel   = ProjectRootElement.Create(Path.Combine(TempDir, "project.csproj"), engine);

            var unpackDir = GetTempPath("unpacked");

            prel.SetProperty("XamarinBuildDownloadDir", unpackDir);

            prel.AddItem(
                "XamarinBuildDownload", "FacebookAndroid-4.17.0", new Dictionary <string, string> {
                { "Url", itemUrl },
                { "Kind", "Uncompressed" },
            });

            AddCoreTargets(prel);

            var project = new ProjectInstance(prel);
            var log     = new MSBuildTestLogger();

            var success = BuildProject(engine, project, "XamarinBuildDownloadGetItemsToDownload", log);

            AssertNoMessagesOrWarnings(log);
            Assert.IsTrue(success);

            var itemToDownload = project.GetItems("XamarinBuildDownloadItemToDownload");

            Assert.IsTrue(itemToDownload.Count == 1);
            Assert.IsTrue(itemToDownload.First().GetMetadata("Url").EvaluatedValue == itemUrl);
        }
Ejemplo n.º 16
0
        public void TestProguardText()
        {
            var engine = new ProjectCollection();
            var prel   = ProjectRootElement.Create(Path.Combine(TempDir, "project.csproj"), engine);

            var intermediateDir = Path.Combine(TempDir, "obj");

            var asm = AssemblyDefinition.CreateAssembly(
                new AssemblyNameDefinition("Xamarin.GooglePlayServices.Basement", new System.Version(1, 0, 0, 0)),
                "Main",
                ModuleKind.Dll
                );
            var dll = Path.Combine(TempDir, "Xamarin.GooglePlayServices.Basement.dll");

            asm.Write(dll);
            prel.AddItem("ReferencePath", dll);


            var unpackDir = GetTempPath("unpacked");

            prel.SetProperty("XamarinBuildDownloadDir", unpackDir);
            prel.SetProperty("TargetFrameworkIdentifier", "MonoAndroid");
            prel.SetProperty("TargetFrameworkVersion", "v7.0");
            prel.SetProperty("OutputType", "Exe");
            prel.SetProperty("IntermediateOutputPath", intermediateDir);

            prel.AddItem(
                "XamarinBuildDownloadPartialZip", "playservices-10.2.1/playservicesbasement", new Dictionary <string, string> {
                { "Url", "https://dl-ssl.google.com/android/repository/google_m2repository_gms_v9_1_rc07_wear_2_0_1_rc3.zip" },
                { "ToFile", "play-services-basement-10.2.1.aar" },
                { "RangeStart", "100833740" },
                { "RangeEnd", "101168014" },
                { "Md5", "1ddf95b31e73f7a79e39df81875797ae" }
            });

            const string resourceName = "__AndroidLibraryProjects__.zip";
            var          aarPath      = "$(XamarinBuildDownloadDir)playservices-10.2.1\\playservicesbasement\\play-services-basement-10.2.1.aar";

            prel.AddItem(
                "XamarinBuildDownloadRestoreAssemblyAar",
                aarPath,
                new Dictionary <string, string> {
                { "AssemblyName", "Xamarin.GooglePlayServices.Basement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" },
                { "LogicalName", resourceName }
            }
                );

            AddCoreTargets(prel);

            var project = new ProjectInstance(prel);
            var log     = new MSBuildTestLogger();

            var success = BuildProject(engine, project, "_XamarinAndroidBuildAarProguardConfigs", log);

            var proguardConfigItems = project.GetItems("ProguardConfiguration");

            AssertNoMessagesOrWarnings(log);
            Assert.IsTrue(success);
            Assert.IsTrue(proguardConfigItems.Any());
        }
Ejemplo n.º 17
0
        public void AddItemWithMetadata()
        {
            ProjectInstance p = GetEmptyProjectInstance();

            var metadata = new List <KeyValuePair <string, string> >();

            metadata.Add(new KeyValuePair <string, string>("m", "m1"));
            metadata.Add(new KeyValuePair <string, string>("n", "n1"));
            metadata.Add(new KeyValuePair <string, string>("o", "o%40"));

            ProjectItemInstance returned = p.AddItem("i", "i1", metadata);

            Assert.True(object.ReferenceEquals(returned, Helpers.MakeList(p.GetItems("i"))[0]));

            foreach (ProjectItemInstance item in p.Items)
            {
                Assert.Same(returned, item);
                Assert.Equal("i1", item.EvaluatedInclude);
                var metadataOut = Helpers.MakeList(item.Metadata);
                Assert.Equal(3, metadataOut.Count);
                Assert.Equal("m1", item.GetMetadataValue("m"));
                Assert.Equal("n1", item.GetMetadataValue("n"));
                Assert.Equal("o@", item.GetMetadataValue("o"));
            }
        }
        /// <summary>
        /// Get all items of type 'i'
        /// </summary>
        private static IList <ProjectItemInstance> GetItems(string content)
        {
            ProjectRootElement xml     = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectInstance    project = new ProjectInstance(xml);

            return(Helpers.MakeList(project.GetItems("i")));
        }
        /// <inheritdoc/>
        public void PredictInputsAndOutputs(
            ProjectInstance projectInstance,
            ProjectPredictionReporter predictionReporter)
        {
            // The symbols file as output directly from the compiler.
            foreach (ProjectItemInstance item in projectInstance.GetItems(DebugSymbolsIntermediatePathItemName))
            {
                predictionReporter.ReportOutputFile(item.EvaluatedInclude);
            }

            // CopyFilesToOutputDirectory copies @(_DebugSymbolsIntermediatePath) items to the output directory using a different item group.
            foreach (ProjectItemInstance item in projectInstance.GetItems(DebugSymbolsOutputPathItemName))
            {
                predictionReporter.ReportOutputFile(item.EvaluatedInclude);
            }
        }
Ejemplo n.º 20
0
        public IEnumerable <ConfigurationMetadata> GetReferences(ProjectInstance requesterInstance)
        {
            IEnumerable <ProjectItemInstance>      references;
            IEnumerable <GlobalPropertiesModifier> globalPropertiesModifiers = null;

            switch (GetProjectType(requesterInstance))
            {
            case ProjectType.OuterBuild:
                references = GetInnerBuildReferences(requesterInstance);
                break;

            case ProjectType.InnerBuild:
                globalPropertiesModifiers = ModifierForNonMultitargetingNodes.Add((parts, reference) => parts.AddPropertyToUndefine(GetInnerBuildPropertyName(requesterInstance)));
                references = requesterInstance.GetItems(ItemTypeNames.ProjectReference);
                break;

            case ProjectType.NonMultitargeting:
                globalPropertiesModifiers = ModifierForNonMultitargetingNodes;
                references = requesterInstance.GetItems(ItemTypeNames.ProjectReference);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            foreach (var projectReference in references)
            {
                if (!String.IsNullOrEmpty(projectReference.GetMetadataValue(ToolsVersionMetadataName)))
                {
                    throw new InvalidOperationException(
                              String.Format(
                                  CultureInfo.InvariantCulture,
                                  ResourceUtilities.GetResourceString(
                                      "ProjectGraphDoesNotSupportProjectReferenceWithToolset"),
                                  projectReference.EvaluatedInclude,
                                  requesterInstance.FullPath));
                }

                var projectReferenceFullPath = projectReference.GetMetadataValue(FullPathMetadataName);

                var referenceGlobalProperties = GetGlobalPropertiesForItem(projectReference, requesterInstance.GlobalPropertiesDictionary, globalPropertiesModifiers);

                var referenceConfig = new ConfigurationMetadata(projectReferenceFullPath, referenceGlobalProperties);

                yield return(referenceConfig);
            }
        }
Ejemplo n.º 21
0
            private static string[] GetTargetFrameworkSubsets(ProjectInstance projectInstance)
            {
                IEnumerable <ITaskItem> taskItems = projectInstance.GetItems(ReferenceInstalledAssemblySubsets);

                string[] targetFrameworkSubsets = (taskItems.Select((Func <ITaskItem, string>)((item) => { return(item.ItemSpec.Trim()); }))).ToArray();

                return(targetFrameworkSubsets);
            }
Ejemplo n.º 22
0
            private static string[] GetLatestTargetFrameworkDirectories(ProjectInstance projectInstance)
            {
                IEnumerable <ITaskItem> taskItems = projectInstance.GetItems(LatestTargetFrameworkDirectoriesName);

                string[] latestTargetFrameworkDirectory = (taskItems.Select((Func <ITaskItem, string>)((item) => { return(item.ItemSpec.Trim()); }))).ToArray();

                return(latestTargetFrameworkDirectory);
            }
Ejemplo n.º 23
0
        public IDictionary <string, string> ResolveAssemblyPaths(string[] assemblySpecs)
        {
            IDictionary <string, string> strs = new Dictionary <string, string>();
            string          str             = "DesignTimeResolveAssemblyReferences";
            string          str1            = "DesignTimeReferencePath";
            ProjectInstance projectInstance = this.Project.CreateProjectInstance();
            StringBuilder   stringBuilder   = new StringBuilder();

            string[] strArrays = assemblySpecs;
            for (int i = 0; i < (int)strArrays.Length; i++)
            {
                stringBuilder.Append(strArrays[i]);
                stringBuilder.Append(";");
            }
            projectInstance.SetProperty("DesignTimeReference", stringBuilder.ToString());
            projectInstance.SetProperty("DesignTimeFindDependencies", "false");
            projectInstance.SetProperty("DesignTimeSilentResolution", "true");
            projectInstance.SetProperty("_FullFrameworkReferenceAssemblyPaths", string.Empty);
            projectInstance.SetProperty("_TargetFrameworkDirectories", string.Empty);
            projectInstance.SetProperty("TargetFrameworkMonikerDisplayName", string.Empty);
            projectInstance.SetProperty("FrameworkPathOverride", string.Empty);
            lock (ReferenceAssemblyResolver.syncLock)
            {
                BuildParameters buildParameter = new BuildParameters(ReferenceAssemblyResolver.projectCollection)
                {
                    OnlyLogCriticalEvents    = true,
                    MaxNodeCount             = 1,
                    SaveOperatingEnvironment = false
                };
                string[]         strArrays1        = new string[] { str };
                BuildRequestData buildRequestDatum = new BuildRequestData(projectInstance, strArrays1, null);
                ReferenceAssemblyResolver.buildManager.Build(buildParameter, buildRequestDatum);
            }
            foreach (ProjectItemInstance item in projectInstance.GetItems(str1))
            {
                if (!this.IsValidItem(item))
                {
                    continue;
                }
                strs.Add(item.GetMetadataValue("OriginalItemSpec"), item.EvaluatedInclude);
            }
            string str2 = Path.Combine(Path.GetTempPath(), "Expression_Blend_CAC0CD0D_3298_4A3D_9EC0_DBFD8306D79F");

            if (!string.IsNullOrEmpty(str2) && Microsoft.Expression.Framework.Documents.PathHelper.DirectoryExists(str2))
            {
                try
                {
                    Directory.Delete(str2, true);
                }
                catch (IOException oException)
                {
                }
                catch (UnauthorizedAccessException unauthorizedAccessException)
                {
                }
            }
            return(strs);
        }
Ejemplo n.º 24
0
 /// <inheritdoc/>
 public void PredictInputsAndOutputs(
     ProjectInstance projectInstance,
     ProjectPredictionReporter predictionReporter)
 {
     foreach (ProjectItemInstance item in projectInstance.GetItems(PageItemName))
     {
         predictionReporter.ReportInputFile(item.EvaluatedInclude);
     }
 }
        /// <inheritdoc/>
        public void PredictInputsAndOutputs(
            ProjectInstance projectInstance,
            ProjectPredictionReporter predictionReporter)
        {
            // The documentation file as output directly from the compiler.
            // Note that this item generally has exactly one item which is the value of $(DocumentationFile),
            // but this item is the one that's actually used so we'll use ti here too since it's included statically.
            foreach (ProjectItemInstance item in projectInstance.GetItems(DocFileItemItemName))
            {
                predictionReporter.ReportOutputFile(item.EvaluatedInclude);
            }

            // CopyFilesToOutputDirectory copies @(DocFileItem) items to the output directory using a different item group.
            foreach (ProjectItemInstance item in projectInstance.GetItems(FinalDocFileItemName))
            {
                predictionReporter.ReportOutputFile(item.EvaluatedInclude);
            }
        }
Ejemplo n.º 26
0
 protected IEnumerable <ProjectItemInstance> GetProjectReferenceItems(ProjectInstance executedProject)
 {
     return(executedProject
            .GetItems("ProjectReference")
            .Where(i => !string.Equals(
                       i.GetMetadataValue("ReferenceOutputAssembly"),
                       bool.FalseString,
                       StringComparison.OrdinalIgnoreCase)));
 }
Ejemplo n.º 27
0
        public void WildcardsInsideTargets()
        {
            string directory = null;
            string file1     = null;
            string file2     = null;
            string file3     = null;

            try
            {
                directory = Path.Combine(Path.GetTempPath(), "WildcardsInsideTargets");
                Directory.CreateDirectory(directory);
                file1 = Path.Combine(directory, "a.exe");
                file2 = Path.Combine(directory, "b.exe");
                file3 = Path.Combine(directory, "c.bat");
                File.WriteAllText(file1, String.Empty);
                File.WriteAllText(file2, String.Empty);
                File.WriteAllText(file3, String.Empty);

                string path = Path.Combine(directory, "*.exe");

                string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t'>
                          <ItemGroup>
                            <i Include='" + path + @"'/>
                          </ItemGroup>
                        </Target>
                    </Project>";

                ProjectInstance projectInstance = GetProjectInstance(content);
                projectInstance.Build();

                Assert.Equal(2, Helpers.MakeList(projectInstance.GetItems("i")).Count);
                Assert.Equal(file1, Helpers.MakeList(projectInstance.GetItems("i"))[0].EvaluatedInclude);
                Assert.Equal(file2, Helpers.MakeList(projectInstance.GetItems("i"))[1].EvaluatedInclude);
            }
            finally
            {
                File.Delete(file1);
                File.Delete(file2);
                File.Delete(file3);
                FileUtilities.DeleteWithoutTrailingBackslash(directory);
            }
        }
Ejemplo n.º 28
0
        /// <inheritdoc/>
        public void PredictInputsAndOutputs(
            ProjectInstance projectInstance,
            ProjectPredictionReporter predictionReporter)
        {
            // This predictor only applies to ccproj files
            if (!projectInstance.FullPath.EndsWith(".ccproj", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            foreach (ProjectItemInstance item in projectInstance.GetItems(ServiceConfigurationItemName))
            {
                predictionReporter.ReportInputFile(item.EvaluatedInclude);
            }

            foreach (ProjectItemInstance item in projectInstance.GetItems(ServiceDefinitionItemName))
            {
                predictionReporter.ReportInputFile(item.EvaluatedInclude);
            }
        }
Ejemplo n.º 29
0
        public void ItemEvaluationCopiesMetadata()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <ItemGroup>
                            <i Include='i1'>
                                <m>m1</m>
                                <n>n%3b%3b</n>
                            </i>
                            <j Include='@(i)'/>
                        </ItemGroup>
                    </Project>";

            ProjectInstance project = GetProjectInstance(content);

            Assert.Single(Helpers.MakeList(project.GetItems("j")));
            Assert.Equal("i1", Helpers.MakeList(project.GetItems("j"))[0].EvaluatedInclude);
            Assert.Equal("m1", Helpers.MakeList(project.GetItems("j"))[0].GetMetadataValue("m"));
            Assert.Equal("n;;", Helpers.MakeList(project.GetItems("j"))[0].GetMetadataValue("n"));
        }
Ejemplo n.º 30
0
        public void ExpandBuiltInMetadataAtPointOfUse_UseInBatching()
        {
            string content =
                ObjectModelHelpers.CleanupFileContents(
                    @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
  <ItemDefinitionGroup>
    <h>
      <m>%(extension)</m>
    </h>
  </ItemDefinitionGroup>
  <ItemGroup>
    <h Include='a.foo;a.bar'/>
  </ItemGroup>
  <Target Name='t'>
    <ItemGroup>
      <i Include=""@(h)"">
         <n Condition=""'%(m)'=='.foo'"">n1</n>
      </i>
    </ItemGroup>
  </Target>
</Project>");

            Project project = new Project(XmlReader.Create(new StringReader(content)));

            ProjectInstance instance = project.CreateProjectInstance();
            MockLogger      l        = new MockLogger();
            List <ILogger>  loggers  = new List <ILogger>()
            {
                l
            };

            instance.Build(loggers);

            ProjectItemInstance item1 = instance.GetItems("i").ElementAt(0);

            Assert.Equal("n1", item1.GetMetadataValue("n"));

            ProjectItemInstance item2 = instance.GetItems("i").ElementAt(1);

            Assert.Equal("", item2.GetMetadataValue("n"));
        }