using System.Linq;
using System.Xml;
using System.Reflection;
+using System.Globalization;
namespace Microsoft.Build.Evaluation
{
}
}
}
+
+ static readonly char [] path_sep = {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar};
+
+ internal static string GetWellKnownMetadata (string name, string file, Func<string,string> getFullPath, string recursiveDir)
+ {
+ switch (name.ToLower (CultureInfo.InvariantCulture)) {
+ case "fullpath":
+ return getFullPath (file);
+ case "rootdir":
+ return Path.GetPathRoot (getFullPath (file));
+ case "filename":
+ return Path.GetFileNameWithoutExtension (file);
+ case "extension":
+ return Path.GetExtension (file);
+ case "relativedir":
+ var idx = file.LastIndexOfAny (path_sep);
+ return idx < 0 ? string.Empty : file.Substring (0, idx + 1);
+ case "directory":
+ var fp = getFullPath (file);
+ return Path.GetDirectoryName (fp).Substring (Path.GetPathRoot (fp).Length);
+ case "recursivedir":
+ return recursiveDir;
+ case "identity":
+ return file;
+ case "modifiedtime":
+ return new FileInfo (getFullPath (file)).LastWriteTime.ToString ("yyyy-MM-dd HH:mm:ss.fffffff");
+ case "createdtime":
+ return new FileInfo (getFullPath (file)).CreationTime.ToString ("yyyy-MM-dd HH:mm:ss.fffffff");
+ case "accessedtime":
+ return new FileInfo (getFullPath (file)).LastAccessTime.ToString ("yyyy-MM-dd HH:mm:ss.fffffff");
+ }
+ return null;
+ }
}
}
{
return metadata.FirstOrDefault (m => m.Name == name);
}
-
- static readonly char [] path_sep = {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar};
-
- static readonly Dictionary<string,Func<ProjectItem,string>> well_known_metadata = new Dictionary<string, Func<ProjectItem,string>> {
- {"FullPath", p => Path.Combine (p.Project.GetFullPath (p.evaluated_include)) },
- {"RootDir", p => Path.GetPathRoot (p.Project.GetFullPath (p.evaluated_include)) },
- {"Filename", p => Path.GetFileNameWithoutExtension (p.evaluated_include) },
- {"Extension", p => Path.GetExtension (p.evaluated_include) },
- {"RelativeDir", p => {
- var idx = p.evaluated_include.LastIndexOfAny (path_sep);
- return idx < 0 ? string.Empty : p.evaluated_include.Substring (0, idx + 1); }
- },
- {"Directory", p => {
- var fp = p.Project.GetFullPath (p.evaluated_include);
- return Path.GetDirectoryName (fp).Substring (Path.GetPathRoot (fp).Length); }
- },
- {"RecursiveDir", p => p.RecursiveDir },
- {"Identity", p => p.EvaluatedInclude },
- {"ModifiedTime", p => new FileInfo (p.Project.GetFullPath (p.evaluated_include)).LastWriteTime.ToString ("yyyy-MM-dd HH:mm:ss.fffffff") },
- {"CreatedTime", p => new FileInfo (p.Project.GetFullPath (p.evaluated_include)).CreationTime.ToString ("yyyy-MM-dd HH:mm:ss.fffffff") },
- {"AccessedTime", p => new FileInfo (p.Project.GetFullPath (p.evaluated_include)).LastAccessTime.ToString ("yyyy-MM-dd HH:mm:ss.fffffff") },
- };
public string GetMetadataValue (string name)
{
- var wellKnown = well_known_metadata.FirstOrDefault (p => p.Key.Equals (name, StringComparison.OrdinalIgnoreCase));
- if (wellKnown.Value != null)
- return wellKnown.Value (this);
+ if (name == null)
+ throw new ArgumentNullException ("name");
+ var wk = ProjectCollection.GetWellKnownMetadata (name, EvaluatedInclude, project.GetFullPath, RecursiveDir);
+ if (wk != null)
+ return wk;
var m = GetMetadata (name);
return m != null ? m.EvaluatedValue : string.Empty;
}
}
internal BuildTaskDatabase TaskDatabase { get; private set; }
+
+ internal string GetFullPath (string pathRelativeToProject)
+ {
+ if (Path.IsPathRooted (pathRelativeToProject))
+ return pathRelativeToProject;
+ return Path.GetFullPath (Path.Combine (Directory, pathRelativeToProject));
+ }
}
}
using Microsoft.Build.Evaluation;
using System.Collections;
using Microsoft.Build.Construction;
+using System.Globalization;
+using System.IO;
namespace Microsoft.Build.Execution
{
public ProjectMetadataInstance GetMetadata (string name)
{
+ if (name == null)
+ throw new ArgumentNullException ("name");
+ // This does not return any Well Known metadata
return Metadata.FirstOrDefault (m => m.Name.Equals (name, StringComparison.OrdinalIgnoreCase));
}
public string GetMetadataValue (string name)
{
+ if (name == null)
+ throw new ArgumentNullException ("name");
+ var wk = ProjectCollection.GetWellKnownMetadata (name, EvaluatedInclude, project.GetFullPath, RecursiveDir);
+ if (wk != null)
+ return wk;
var m = GetMetadata (name);
return m != null ? m.EvaluatedValue : null;
}
throw new InvalidOperationException (string.Format ("Task {0} does not have property {1}", ti.Name, p.Key));
if (!prop.CanWrite)
throw new InvalidOperationException (string.Format ("Task {0} has property {1} but it is read-only.", ti.Name, p.Key));
- prop.SetValue (task, ConvertTo (value, prop.PropertyType), null);
+ var valueInstance = ConvertTo (value, prop.PropertyType);
+ prop.SetValue (task, valueInstance, null);
}
// Do execute task.
object ConvertTo (string source, Type targetType)
{
if (targetType == typeof (ITaskItem) || targetType.IsSubclassOf (typeof (ITaskItem)))
- return new TargetOutputTaskItem () { ItemSpec = source };
+ return new TargetOutputTaskItem () { ItemSpec = WindowsCompatibilityExtensions.NormalizeFilePath (source) };
if (targetType.IsArray)
return new ArrayList (source.Split (';').Where (s => !string.IsNullOrEmpty (s)).Select (s => ConvertTo (s, targetType.GetElementType ())).ToArray ())
.ToArray (targetType.GetElementType ());
}
public string GetMetadata (string metadataName)
{
+ var wk = ProjectCollection.GetWellKnownMetadata (metadataName, ItemSpec, Path.GetFullPath, null);
+ if (wk != null)
+ return wk;
return (string) metadata [metadataName];
}
public void RemoveMetadata (string metadataName)
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Construction;
+using Microsoft.Build.Evaluation;
+using System.IO;
namespace Microsoft.Build.Internal
{
public ProjectTaskItem (ProjectItemElement item, string evaluatedIncludePart)
{
this.item = item;
- this.evaluated_include_part = evaluatedIncludePart;
+ this.evaluated_include_part = WindowsCompatibilityExtensions.NormalizeFilePath (evaluatedIncludePart);
}
#region ITaskItem implementation
System.Collections.IDictionary ITaskItem.CloneCustomMetadata ()
}
string ITaskItem.GetMetadata (string metadataName)
{
+ var wk = ProjectCollection.GetWellKnownMetadata (metadataName, evaluated_include_part, Path.GetFullPath, null);
+ if (wk != null)
+ return wk;
var mde = item.Metadata.FirstOrDefault (m => m.Name == metadataName);
return mde != null ? mde.Value : null;
}