public void OutputPropertyExists () { string project_xml = @" <Project DefaultTargets='Build' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <PropertyGroup> <C>False</C> </PropertyGroup> <Target Name='Build' DependsOnTargets='ResolveReferences' /> <Target Name='Build2' DependsOnTargets='Bar' /> <Target Name='ResolveReferences' DependsOnTargets='Foo;Bar' /> <Target Name='Foo'> <CreateProperty Value='True'> <Output TaskParameter='Value' PropertyName='C' /> </CreateProperty> </Target> <Target Name='Bar' Condition='!($(C))' DependsOnTargets='ResolveReferences'> </Target> </Project>"; var xml = XmlReader.Create (new StringReader(project_xml)); var root = ProjectRootElement.Create (xml); var proj = new ProjectInstance (root); Assert.AreEqual (5, proj.Targets.Count, "#1"); var foo = proj.Targets ["Foo"]; Assert.IsNotNull (foo, "#2"); Assert.AreEqual (1, foo.Tasks.Count, "#3"); var cp = foo.Tasks.First (); Assert.AreEqual (1, cp.Outputs.Count, "#4"); var po = cp.Outputs.First () as ProjectTaskOutputPropertyInstance; Assert.IsNotNull (po, "#5"); Assert.AreEqual ("C", po.PropertyName, "#5"); proj.Build ("Build", null); Assert.AreEqual (string.Empty, foo.Outputs, "#6"); Assert.AreEqual ("True", proj.GetPropertyValue ("C"), "#7"); }
private static string[] GetPdtarSearchPaths(ProjectInstance projectInstance) { string val = projectInstance.GetPropertyValue(ProjectDesignTimeAssemblyResolutionSearchPaths).Trim(); string[] _pdtarSearchPaths = val.Split(';').Select(s => s.Trim()).ToArray(); return _pdtarSearchPaths; }
private static bool GetIgnoreDefaultInstalledAssemblySubsetTables(ProjectInstance projectInstance) { bool ignoreDefaultInstalledAssemblySubsetTables = false; string val = projectInstance.GetPropertyValue(IgnoreInstalledAssemblySubsetTables).Trim(); if (!String.IsNullOrEmpty(val)) { if (val == Boolean.TrueString || val == Boolean.FalseString) { ignoreDefaultInstalledAssemblySubsetTables = Convert.ToBoolean(val, CultureInfo.InvariantCulture); } } return ignoreDefaultInstalledAssemblySubsetTables; }
private static string[] GetFullTargetFrameworkSubsetNames(ProjectInstance projectInstance) { string val = projectInstance.GetPropertyValue(FullReferenceAssemblyNames).Trim(); string[] fullTargetFrameworkSubsetNames = val.Split(';').Select(s => s.Trim()).ToArray(); return fullTargetFrameworkSubsetNames; }
protected static string GetTargetedRuntimeVersion(ProjectInstance projectInstance) { string val = projectInstance.GetPropertyValue(TargetedRuntimeVersionName).Trim(); return val; }
/// <summary> /// Retrieves a dictionary representing the global properties which should be transferred to a metaproject. /// </summary> /// <param name="traversalProject">The traversal from which the global properties should be obtained.</param> /// <returns>A dictionary of global properties.</returns> private IDictionary<string, string> GetMetaprojectGlobalProperties(ProjectInstance traversalProject) { Dictionary<string, string> properties = new Dictionary<string, string>(_metaprojectGlobalProperties.Length, StringComparer.OrdinalIgnoreCase); foreach (Tuple<string, string> property in _metaprojectGlobalProperties) { if (property.Item2 == null) { properties[property.Item1] = EscapingUtilities.Escape(traversalProject.GetPropertyValue(property.Item1)); } else { properties[property.Item1] = EscapingUtilities.Escape(property.Item2); } } // Now provide any which are explicitly set on the solution foreach (ProjectPropertyInstance globalProperty in traversalProject.GlobalPropertiesDictionary) { properties[globalProperty.Name] = ((IProperty)globalProperty).EvaluatedValueEscaped; } // If we have a sub-toolset version, it will be set on the P2P from the solution metaproj, so we need // to make sure it's set here, too, so the global properties will match. if (traversalProject.SubToolsetVersion != null) { if (traversalProject.SubToolsetVersion.Equals("4.0", StringComparison.OrdinalIgnoreCase)) { properties[Constants.SubToolsetVersionPropertyName] = traversalProject.SubToolsetVersion; } } return properties; }
private static string GetTargetProcessorArchitecture(ProjectInstance projectInstance) { string val = projectInstance.GetPropertyValue(ProcessorArchitecture).Trim(); return val; }
private static string GetTargetFrameworkMonikerDisplayName(ProjectInstance projectInstance) { string val = projectInstance.GetPropertyValue(TargetFrameworkMonikerDisplayNameName).Trim(); return val; }
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"); }
static Guid getProjectGuid(ProjectInstance instance) { var projectGuid = instance.GetPropertyValue("ProjectGuid"); if (projectGuid == "") throw new Exception("project has no Guid"); return Guid.Parse(projectGuid); }
[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"); }
public void PropertyOverrides () { string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <PropertyGroup> <X>x</X> </PropertyGroup> <PropertyGroup> <X>y</X> </PropertyGroup> </Project>"; var xml = XmlReader.Create (new StringReader (project_xml)); var root = ProjectRootElement.Create (xml); root.FullPath = "ProjectTest.BuildCSharpTargetBuild.proj"; var proj = new ProjectInstance (root); Assert.AreEqual ("y", proj.GetPropertyValue ("X"), "#1"); }
protected static string GetTargetFrameworkMoniker(ProjectInstance projectInstance) { string val = projectInstance.GetPropertyValue(TargetFrameworkMonikerName).Trim(); return val; }
private static string GetProfileName(ProjectInstance projectInstance) { string val = projectInstance.GetPropertyValue(TargetFrameworkProfile).Trim(); return val; }
public void GetSubToolsetVersion_FromConstructor() { string originalVisualStudioVersion = Environment.GetEnvironmentVariable("VisualStudioVersion"); try { Environment.SetEnvironmentVariable("VisualStudioVersion", "ABC"); string projectContent = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <Target Name='t'> <Message Text='Hello'/> </Target> </Project>"; ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(projectContent))); IDictionary<string, string> globalProperties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); globalProperties.Add("VisualStudioVersion", "ABCD"); IDictionary<string, string> projectCollectionGlobalProperties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); projectCollectionGlobalProperties.Add("VisualStudioVersion", "ABCDE"); ProjectInstance p = new ProjectInstance(xml, globalProperties, "4.0", "ABCDEF", new ProjectCollection(projectCollectionGlobalProperties)); Assert.Equal("4.0", p.Toolset.ToolsVersion); Assert.Equal("ABCDEF", p.SubToolsetVersion); Assert.Equal("ABCDEF", p.GetPropertyValue("VisualStudioVersion")); } finally { Environment.SetEnvironmentVariable("VisualStudioVersion", originalVisualStudioVersion); } }
private static string GetStateFile(ProjectInstance projectInstance) { string intermediatePath = projectInstance.GetPropertyValue(IntermediateOutputPath).Trim(); intermediatePath = GetFullPathInProjectContext(projectInstance, intermediatePath); string stateFile = Path.Combine(intermediatePath, "DesignTimeResolveAssemblyReferences.cache"); return stateFile; }
private static string[] GetAllowedAssemblyExtensions(ProjectInstance projectInstance) { string[] allowedAssemblyExtensions; string val = projectInstance.GetPropertyValue(AllowedReferenceAssemblyFileExtensions).Trim(); allowedAssemblyExtensions = val.Split(';').Select(s => s.Trim()).ToArray(); return allowedAssemblyExtensions; }
private static string GetTargetFrameworkVersion(ProjectInstance projectInstance) { string val = projectInstance.GetPropertyValue(TargetFrameworkVersionName).Trim(); return val; }
private static string[] GetFullFrameworkFolders(ProjectInstance projectInstance) { string val = projectInstance.GetPropertyValue(FullFrameworkReferenceAssemblyPaths).Trim(); string[] _fullFrameworkFolders = val.Split(';').Select(s => s.Trim()).ToArray(); return _fullFrameworkFolders; }
private string[] GetTargetFrameworkDirectories(ProjectInstance projectInstance) { if (TargetFrameworkDirectories == null) { string val = projectInstance.GetPropertyValue(TargetFrameworkDirectory).Trim(); TargetFrameworkDirectories = val.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()) .Where(s => s.Length > 0) .ToArray(); } return TargetFrameworkDirectories; }
static string GetFullPathInProjectContext(ProjectInstance projectInstance, string path) { string fullPath = path; if (!Path.IsPathRooted(path)) { string projectDir = projectInstance.GetPropertyValue(MSBuildProjectDirectory).Trim(); fullPath = Path.Combine(projectDir, path); fullPath = Path.GetFullPath(fullPath); } return fullPath; }
/// <summary> /// The value to be passed to the ToolsVersion attribute of the MSBuild task used to directly build a project. /// </summary> private string GetToolsVersionMetadataForDirectMSBuildTask(ProjectInstance traversalProject) { string directProjectToolsVersion = traversalProject.GetPropertyValue("ProjectToolsVersion"); return directProjectToolsVersion; }
public void BuildCommonResolveAssemblyReferences () { string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <Import Project='$(MSBuildToolsPath)\Microsoft.Common.targets' /> <ItemGroup> <Reference Include='System.Core' /> <Reference Include='System.Xml' /> </ItemGroup> </Project>"; var xml = XmlReader.Create (new StringReader (project_xml)); var root = ProjectRootElement.Create (xml); root.FullPath = "BuildManagerTest.BuildCommonResolveAssemblyReferences.proj"; var proj = new ProjectInstance (root); var manager = new BuildManager (); var parameters = new BuildParameters () { Loggers = new ILogger [] {new ConsoleLogger (LoggerVerbosity.Diagnostic)} }; var request = new BuildRequestData (proj, new string [] {"ResolveAssemblyReferences"}); Assert.AreEqual (string.Empty, proj.GetPropertyValue ("TargetFrameworkDirectory"), "#1-1"); var result = manager.Build (parameters, request); Assert.AreNotEqual (string.Empty, proj.GetPropertyValue ("TargetFrameworkDirectory"), "#1-2"); // filled during build. Assert.IsTrue (result.ResultsByTarget.ContainsKey ("GetFrameworkPaths"), "#2-1"); Assert.IsTrue (result.ResultsByTarget.ContainsKey ("PrepareForBuild"), "#2-2"); Assert.IsTrue (result.ResultsByTarget.ContainsKey ("ResolveAssemblyReferences"), "#2-3"); var items = proj.GetItems ("ReferencePath"); Assert.AreEqual (2, items.Count (), "#3"); var syscore = items.FirstOrDefault (i => Path.GetFileName (i.EvaluatedInclude) == "System.Core.dll"); var sysxml = items.FirstOrDefault (i => Path.GetFileName (i.EvaluatedInclude) == "System.Xml.dll"); Assert.IsNotNull (syscore, "#4-1"); Assert.IsNotNull (sysxml, "#4-2"); Assert.IsTrue (File.Exists (syscore.EvaluatedInclude), "#5-1"); Assert.IsTrue (File.Exists (sysxml.EvaluatedInclude), "#5-1"); Assert.AreEqual (BuildResultCode.Success, result.OverallResult, "#6"); }