public static bool IsValidName(string name) { return(!string.IsNullOrEmpty(name) && MSBuildInternals.Escape(name) == name && name.Trim() == name && FileUtility.IsValidDirectoryEntryName(name) && name.IndexOf('\'') < 0 && name.IndexOf('.') < 0); }
void WriteAdditionalTargetsToTempFile(Dictionary <string, string> globalProperties) { // Using projects with in-memory modifications doesn't work with parallel build. // As a work-around, we'll write our modifications to a file and force MSBuild to include that file using a custom property. temporaryFileName = Path.GetTempFileName(); using (XmlWriter w = new XmlTextWriter(temporaryFileName, Encoding.UTF8)) { const string xmlNamespace = "http://schemas.microsoft.com/developer/msbuild/2003"; w.WriteStartElement("Project", xmlNamespace); foreach (string import in additionalTargetFiles) { w.WriteStartElement("Import", xmlNamespace); w.WriteAttributeString("Project", MSBuildInternals.Escape(import)); w.WriteEndElement(); } if (globalProperties.ContainsKey("BuildingInsideVisualStudio")) { // When we set BuildingInsideVisualStudio, MSBuild skips its own change detection // because in Visual Studio, the host compiler does the change detection. // We override the target '_ComputeNonExistentFileProperty' which is responsible // for recompiling each time - our _ComputeNonExistentFileProperty does nothing, // which re-enables the MSBuild's usual change detection. w.WriteStartElement("Target", xmlNamespace); w.WriteAttributeString("Name", "_ComputeNonExistentFileProperty"); w.WriteEndElement(); } // 'MsTestToolsTargets' is preferred because it's at the end of the MSBuild 3.5 and 4.0 target file, // but on MSBuild 2.0 we need to fall back to 'CodeAnalysisTargets'. string hijackedProperty = "MsTestToolsTargets"; if (projectMinimumSolutionVersion == SolutionFormatVersion.VS2005) { hijackedProperty = "CodeAnalysisTargets"; } // because we'll replace the hijackedProperty, manually write the corresponding include if (globalProperties.ContainsKey(hijackedProperty)) { // global properties passed to MSBuild are not be evaluated (and are not escaped), // so we need to escape them for writing them into an MSBuild file w.WriteStartElement("Import", xmlNamespace); w.WriteAttributeString("Project", MSBuildInternals.Escape(globalProperties[hijackedProperty])); w.WriteEndElement(); } w.WriteEndElement(); // inject our imports at the end of 'Microsoft.Common.Targets' by replacing the hijackedProperty. globalProperties[hijackedProperty] = temporaryFileName; } #if DEBUG LoggingService.Debug(File.ReadAllText(temporaryFileName)); #endif }
/// <summary> /// Sets the value of the specified meta data item. The value is escaped before /// setting it to ensure characters like ';' or '$' are not interpreted by MSBuild. /// Setting value to null or an empty string results in removing the metadata item. /// </summary> public void SetEvaluatedMetadata(string metadataName, string value) { if (string.IsNullOrEmpty(value)) { RemoveMetadata(metadataName); } else { lock (SyncRoot) { if (buildItem != null) { buildItem.SetEvaluatedMetadata(metadataName, value); } else { virtualMetadata[metadataName] = MSBuildInternals.Escape(value); } } } }
public void SetEvaluatedMetadata(string name, string value) { item.SetMetadataValue(name, MSBuildInternals.Escape(value)); }