public override void Initialize (OptionsDialog dialog, object dataObject) { project = dataObject as DotNetProject; propertyGroup = project.MSBuildProject.GetNuGetMetadataPropertyGroup (); packOnBuild = propertyGroup.GetValue ("PackOnBuild", false); base.Initialize (dialog, dataObject); }
void RemoveMSBuildProjectNameDerivedProperties(MSBuildPropertyGroup globalPropertyGroup) { string msbuildProjectName = globalPropertyGroup.ParentProject.FileName.FileNameWithoutExtension; if (!hasAssemblyName) { globalPropertyGroup.RemovePropertyIfHasDefaultValue("AssemblyName", msbuildProjectName); } if (!hasRootNamespace) { globalPropertyGroup.RemovePropertyIfHasDefaultValue("RootNamespace", msbuildProjectName); } }
public void TryGetLanguageVersion_SucceedsWithValidLanguageVersion() { // Arrange var projectProperties = new MSBuildPropertyGroup(); projectProperties.SetValue("RazorLangVersion", "1.0"); // Act var result = DefaultRazorProjectHost.TryGetLanguageVersion(projectProperties, out var languageVersion); // Assert Assert.True(result); Assert.Same(RazorLanguageVersion.Version_1_0, languageVersion); }
public void TryGetLanguageVersion_FailsIfEmptyLanguageVersion() { // Arrange var projectProperties = new MSBuildPropertyGroup(); projectProperties.SetValue("RazorLangVersion", string.Empty); // Act var result = DefaultRazorProjectHost.TryGetLanguageVersion(projectProperties, out var languageVersion); // Assert Assert.False(result); Assert.Null(languageVersion); }
public void TryGetConfiguration_SucceedsWithAllPreRequisites() { // Arrange var expectedLanguageVersion = RazorLanguageVersion.Version_1_0; var expectedConfigurationName = "Razor-Test"; var expectedExtension1Name = "Extension1"; var expectedExtension2Name = "Extension2"; var expectedRazorConfigurationItem = new TestMSBuildItem("RazorConfiguration") { Include = expectedConfigurationName, }; expectedRazorConfigurationItem.TestMetadata.SetValue("Extensions", "Extension1;Extension2"); var projectItems = new IMSBuildItemEvaluated[] { new TestMSBuildItem("RazorConfiguration") { Include = "UnconfiguredRazorConfiguration", }, new TestMSBuildItem("RazorExtension") { Include = "UnconfiguredExtensionName", }, new TestMSBuildItem("RazorExtension") { Include = expectedExtension1Name, }, new TestMSBuildItem("RazorExtension") { Include = expectedExtension2Name, }, expectedRazorConfigurationItem, }; var projectProperties = new MSBuildPropertyGroup(); projectProperties.SetValue("RazorDefaultConfiguration", expectedConfigurationName); projectProperties.SetValue("RazorLangVersion", "1.0"); // Act var result = DefaultRazorProjectHost.TryGetConfiguration(projectProperties, projectItems, out var configuration); // Assert Assert.True(result); Assert.Equal(expectedLanguageVersion, configuration.LanguageVersion); Assert.Equal(expectedConfigurationName, configuration.ConfigurationName); Assert.Collection( configuration.Extensions, extension => Assert.Equal(expectedExtension1Name, extension.ExtensionName), extension => Assert.Equal(expectedExtension2Name, extension.ExtensionName)); }
public void TryGetDefaultConfiguration_FailsIfEmptyConfiguration() { // Arrange var projectProperties = new MSBuildPropertyGroup(); projectProperties.SetValue("RazorDefaultConfiguration", string.Empty); // Act var result = DefaultRazorProjectHost.TryGetDefaultConfiguration(projectProperties, out var defaultConfiguration); // Assert Assert.False(result); Assert.Null(defaultConfiguration); }
public void TryGetLanguageVersion_SucceedsWithUnknownLanguageVersion_DefaultsToLatest() { // Arrange var projectProperties = new MSBuildPropertyGroup(); projectProperties.SetValue("RazorLangVersion", "13.37"); // Act var result = DefaultRazorProjectHost.TryGetLanguageVersion(projectProperties, out var languageVersion); // Assert Assert.True(result); Assert.Same(RazorLanguageVersion.Latest, languageVersion); }
public void TryGetConfiguration_FailsIfNoLanguageVersion() { // Arrange var projectProperties = new MSBuildPropertyGroup(); projectProperties.SetValue("RazorDefaultConfiguration", "Razor-13.37"); var projectItems = new IMSBuildItemEvaluated[0]; // Act var result = DefaultRazorProjectHost.TryGetConfiguration(projectProperties, projectItems, out var configuration); // Assert Assert.False(result); Assert.Null(configuration); }
public void TryGetDefaultConfiguration_SucceedsWithValidConfiguration() { // Arrange var expectedConfiguration = "Razor-13.37"; var projectProperties = new MSBuildPropertyGroup(); projectProperties.SetValue("RazorDefaultConfiguration", expectedConfiguration); // Act var result = DefaultRazorProjectHost.TryGetDefaultConfiguration(projectProperties, out var defaultConfiguration); // Assert Assert.True(result); Assert.Equal(expectedConfiguration, defaultConfiguration); }
public static void RemovePropertyIfHasDefaultValue( this MSBuildPropertyGroup propertyGroup, string propertyName, string defaultPropertyValue) { if (!propertyGroup.HasProperty(propertyName)) { return; } if (propertyGroup.GetValue(propertyName) == defaultPropertyValue) { propertyGroup.RemoveProperty(propertyName); } }
private static CsProjFile CreateCore(MSBuildProject project, string fileName) { MSBuildPropertyGroup arg_42_0; if ((arg_42_0 = project.PropertyGroups.FirstOrDefault((MSBuildPropertyGroup x) => x.Properties.Any((MSBuildProperty p) => p.Name == "ProjectGuid"))) == null) { arg_42_0 = (project.PropertyGroups.FirstOrDefault <MSBuildPropertyGroup>() ?? project.AddNewPropertyGroup(true)); } MSBuildPropertyGroup group = arg_42_0; group.SetPropertyValue("ProjectGuid", Guid.NewGuid().ToString().ToUpper(), true); CsProjFile file = new CsProjFile(fileName, project); file.AssemblyName = (file.RootNamespace = file.ProjectName); return(file); }
public static FrameworkName Detect(MSBuildProject project) { MSBuildPropertyGroup group = project.PropertyGroups.FirstOrDefault((MSBuildPropertyGroup x) => x.Properties.Any((MSBuildProperty p) => p.Name.Contains("TargetFramework"))); string identifier = ".NETFramework"; string versionString = "v4.0"; string profile = null; if (group != null) { identifier = (group.GetPropertyValue("TargetFrameworkIdentifier") ?? ".NETFramework"); versionString = (group.GetPropertyValue("TargetFrameworkVersion") ?? "v4.0"); profile = group.GetPropertyValue("TargetFrameworkProfile"); } Version version = Version.Parse(versionString.Replace("v", "").Replace("V", "")); return(new FrameworkName(identifier, version, profile)); }
internal override void ReadChildElement (MSBuildXmlReader reader) { MSBuildObject ob = null; switch (reader.LocalName) { case "ItemGroup": ob = new MSBuildItemGroup (); break; case "PropertyGroup": ob = new MSBuildPropertyGroup (); break; case "ImportGroup": ob = new MSBuildImportGroup (); break; case "Choose": ob = new MSBuildChoose (); break; default: ob = new MSBuildXmlElement (); break; } if (ob != null) { ob.ParentNode = this; ob.Read (reader); ChildNodes = ChildNodes.Add (ob); } else reader.Read (); }
bool GetProperty(MSBuildPropertyGroup propertyGroup, string name, bool defaultValue) { string value = GetProperty(propertyGroup, name); if (string.IsNullOrEmpty(value)) { return(defaultValue); } bool result = false; if (bool.TryParse(value, out result)) { return(result); } return(defaultValue); }
void Update(MSBuildProject project) { MSBuildPropertyGroup propertyGroup = project.GetNuGetMetadataPropertyGroup(); SetProperty(propertyGroup, PackageIdPropertyName, Id); SetProperty(propertyGroup, "PackageVersion", Version); SetProperty(propertyGroup, "Authors", Authors); SetProperty(propertyGroup, "DevelopmentDependency", DevelopmentDependency); SetProperty(propertyGroup, "PackageIconUrl", IconUrl); SetProperty(propertyGroup, "NeutralLanguage", Language); SetProperty(propertyGroup, "PackageLicenseUrl", LicenseUrl); SetProperty(propertyGroup, "PackageRequireLicenseAcceptance", RequireLicenseAcceptance); SetProperty(propertyGroup, "Owners", Owners); SetProperty(propertyGroup, "PackageProjectUrl", ProjectUrl); SetProperty(propertyGroup, "PackageReleaseNotes", ReleaseNotes); SetProperty(propertyGroup, "Summary", Summary); SetProperty(propertyGroup, "PackageTags", Tags); SetProperty(propertyGroup, "Title", Title); }
void Load(MSBuildProject project) { MSBuildPropertyGroup propertyGroup = project.GetNuGetMetadataPropertyGroup(); Id = GetProperty(propertyGroup, PackageIdPropertyName); Version = GetProperty(propertyGroup, "PackageVersion"); Authors = GetProperty(propertyGroup, "Authors"); DevelopmentDependency = GetProperty(propertyGroup, "DevelopmentDependency", false); IconUrl = GetProperty(propertyGroup, "PackageIconUrl"); Language = GetProperty(propertyGroup, "NeutralLanguage"); LicenseUrl = GetProperty(propertyGroup, "PackageLicenseUrl"); Owners = GetProperty(propertyGroup, "Owners"); ProjectUrl = GetProperty(propertyGroup, "PackageProjectUrl"); ReleaseNotes = GetProperty(propertyGroup, "PackageReleaseNotes"); RequireLicenseAcceptance = GetProperty(propertyGroup, "PackageRequireLicenseAcceptance", false); Summary = GetProperty(propertyGroup, "Summary"); Tags = GetProperty(propertyGroup, "PackageTags"); Title = GetProperty(propertyGroup, "Title"); }
void CreateMSBuildProject() { msbuildProject.ToolsVersion = GetToolsVersion(); msbuildProject.DefaultTargets = "Build"; MSBuildPropertyGroup propertyGroup = msbuildProject.PropertyGroups.FirstOrDefault(); if (propertyGroup != null) { msbuildProject.Remove(propertyGroup); } string projectGuid = GetProjectGuid(dnxProject.ItemId); string rootNamespace = dnxProject.DefaultNamespace; AddVisualStudioProperties(); MSBuildPropertyGroup globals = AddGlobalsProperties(projectGuid, rootNamespace); AddSchemaVersion(); AddDotNetTargets(); AddDotNetCoreProps(globals); }
public void TryGetConfiguration_SucceedsWithoutConfiguredExtensionNames() { // Arrange var projectProperties = new MSBuildPropertyGroup(); projectProperties.SetValue("RazorDefaultConfiguration", "Razor-13.37"); projectProperties.SetValue("RazorLangVersion", "1.0"); var projectItems = new IMSBuildItemEvaluated[] { new TestMSBuildItem("RazorConfiguration") { Include = "Razor-13.37", }, }; // Act var result = DefaultRazorProjectHost.TryGetConfiguration(projectProperties, projectItems, out var configuration); // Assert Assert.True(result); Assert.Empty(configuration.Extensions); }
internal override void ReadChildElement (MSBuildXmlReader reader) { MSBuildObject ob = null; switch (reader.LocalName) { case "ItemGroup": ob = new MSBuildItemGroup (); break; case "PropertyGroup": ob = new MSBuildPropertyGroup (); break; } if (ob != null) { ob.ParentNode = this; ob.Read (reader); ChildNodes = ChildNodes.Add (ob); return; } var task = new MSBuildTask (); task.ParentNode = this; task.Read (reader); ChildNodes = ChildNodes.Add (task); }
void Evaluate (ProjectInfo project, MSBuildEvaluationContext context, MSBuildPropertyGroup group) { if (!string.IsNullOrEmpty (group.Condition) && !SafeParseAndEvaluate (project, context, group.Condition, true)) return; foreach (var prop in group.GetProperties ()) Evaluate (project, context, prop); }
void AddSchemaVersion() { MSBuildPropertyGroup propertyGroup = AddPropertyGroup(); AddProperty(propertyGroup, "SchemaVersion", "2.0"); }
void AddDotNetCoreProps(MSBuildPropertyGroup globals) { AddImport(@"$(VSToolsPath)\DotNet\Microsoft.DotNet.Props", "'$(VSToolsPath)' != ''", globals); }
MSBuildProperty AddProperty(MSBuildPropertyGroup propertyGroup, string name, string unevaluatedValue) { propertyGroup.SetValue(name, unevaluatedValue); return(propertyGroup.GetProperty(name)); }
void SetProperty (MSBuildPropertyGroup propertyGroup, string name, string value) { if (string.IsNullOrEmpty (value)) propertyGroup.RemoveProperty (name); else propertyGroup.SetValue (name, value); }
public override MSBuildPropertyGroup AddNewPropertyGroup (MSBuildPropertyGroup beforeGroup = null) { var g = new ProperyGroupData (this); if (beforeGroup != null) { var i = propertyGroups.IndexOf (beforeGroup); if (i != -1) { propertyGroups.Insert (i, g); return g; } } propertyGroups.Add (g); return g; }
public override void RemovePropertyGroup (MSBuildPropertyGroup grp) { propertyGroups.Remove (grp); }
string GetProperty(MSBuildPropertyGroup propertyGroup, string name) { return(propertyGroup.GetProperty(name)?.Value); }
public TestMSBuildItem(string name) { _name = name; _metadata = new MSBuildPropertyGroup(); }
public MSBuildPropertyGroup AddNewPropertyGroup (bool insertAtEnd = true, MSBuildObject beforeObject = null) { var group = new MSBuildPropertyGroup (); AddPropertyGroup (group, insertAtEnd); return group; }
void AddPropertyWithNotEmptyCondition(MSBuildPropertyGroup propertyGroup, string name, string unevaluatedValue) { string condition = String.Format("'$({0})' == ''", name); propertyGroup.SetValue(name, unevaluatedValue, condition: condition); }
public void AddPropertyGroup (MSBuildPropertyGroup group, bool insertAtEnd = true, MSBuildObject beforeObject = null) { AssertCanModify (); if (group.ParentProject != null) throw new InvalidOperationException ("Group already belongs to a project"); group.ParentNode = this; bool added = false; if (beforeObject != null) { var index = ChildNodes.IndexOf (beforeObject); if (index != -1) { ChildNodes = ChildNodes.Insert (index, group); added = true; } } if (!added) { if (insertAtEnd) { var last = ChildNodes.FindLastIndex (g => g is MSBuildPropertyGroup); if (last != -1) { ChildNodes = ChildNodes.Insert (last + 1, group); added = true; } } else { var first = ChildNodes.FindIndex (g => g is MSBuildPropertyGroup); if (first != -1) { ChildNodes = ChildNodes.Insert (first, group); added = true; } } if (!added) { var first = ChildNodes.FindIndex (g => g is MSBuildItemGroup); if (first != -1) ChildNodes = ChildNodes.Insert (first, group); else ChildNodes = ChildNodes.Add (group); } } group.ResetIndent (true); NotifyChanged (); }
internal IPropertySet GetPropertiesLinkedToGroup (MSBuildPropertyGroup group) { evaluatedProperties.LinkToGroup (group); return evaluatedProperties; }
void SetProperty (MSBuildPropertyGroup propertyGroup, string name, bool value) { if (value) propertyGroup.SetValue (name, value); else propertyGroup.RemoveProperty (name); }
public MSBuildItem () { metadata = new MSBuildPropertyGroup (); metadata.UppercaseBools = true; metadata.ParentNode = this; }
string GetProperty (MSBuildPropertyGroup propertyGroup, string name) { return propertyGroup.GetProperty (name)?.Value; }
bool GetProperty (MSBuildPropertyGroup propertyGroup, string name, bool defaultValue) { string value = GetProperty (propertyGroup, name); if (string.IsNullOrEmpty (value)) return defaultValue; bool result = false; if (bool.TryParse (value, out result)) return result; return defaultValue; }
public static bool HasNuGetMetadata(this DotNetProject project) { MSBuildPropertyGroup propertyGroup = project.MSBuildProject.GetNuGetMetadataPropertyGroup(); return(propertyGroup.HasProperty("PackageId")); }
public MSBuildPropertyGroup AddNewPropertyGroup (bool insertAtEnd) { var group = new MSBuildPropertyGroup (); AddPropertyGroup (group, insertAtEnd); return group; }