108 lines
5.2 KiB
Plaintext
108 lines
5.2 KiB
Plaintext
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||
|
<UsingTask TaskName="CheckForPackages" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
|
||
|
<ParameterGroup>
|
||
|
<Packages ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
|
||
|
<PackagesDir ParameterType="System.String" Required="true" />
|
||
|
<CompactMessage ParameterType="System.Boolean" Required="false" />
|
||
|
</ParameterGroup>
|
||
|
<Task>
|
||
|
<Using Namespace="System" />
|
||
|
<Using Namespace="System.Collections.Generic" />
|
||
|
<Using Namespace="System.IO" />
|
||
|
<Using Namespace="System.Linq" />
|
||
|
<Using Namespace="Microsoft.Build.Framework" />
|
||
|
<Using Namespace="Microsoft.Build.Utilities" />
|
||
|
<Code Type="Fragment" Language="cs">
|
||
|
<![CDATA[
|
||
|
try {
|
||
|
string[] dirs = Directory.GetDirectories(PackagesDir);
|
||
|
var missingPackages = new List<string>();
|
||
|
|
||
|
foreach (ITaskItem package in Packages) {
|
||
|
string packageSpec = package.ItemSpec;
|
||
|
bool found = false;
|
||
|
|
||
|
foreach (var dir in dirs)
|
||
|
if (Path.GetFileName(dir).StartsWith(packageSpec, StringComparison.OrdinalIgnoreCase)) {
|
||
|
found = true;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
if (!found)
|
||
|
missingPackages.Add(packageSpec);
|
||
|
}
|
||
|
|
||
|
if (missingPackages.Any()) {
|
||
|
if (CompactMessage) {
|
||
|
Log.LogError("NuGet package restore is not currently enabled. For more information, please see: http://aspnetwebstack.codeplex.com/wikipage?title=NuGet+Packages");
|
||
|
}
|
||
|
else {
|
||
|
Log.LogMessage(MessageImportance.High, "The following NuGet packages have not yet been downloaded:");
|
||
|
|
||
|
foreach (var missingPackage in missingPackages)
|
||
|
Log.LogMessage(MessageImportance.High, " " + missingPackage);
|
||
|
|
||
|
Log.LogMessage(MessageImportance.High, "For more information on enabling package restore, please see:");
|
||
|
Log.LogMessage(MessageImportance.High, "http://aspnetwebstack.codeplex.com/wikipage?title=NuGet+Packages");
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
catch (Exception ex) {
|
||
|
Log.LogErrorFromException(ex);
|
||
|
return false;
|
||
|
}
|
||
|
]]>
|
||
|
</Code>
|
||
|
</Task>
|
||
|
</UsingTask>
|
||
|
|
||
|
<UsingTask TaskName="RegexReplace" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
|
||
|
<ParameterGroup>
|
||
|
<Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
|
||
|
<Find ParameterType="System.String" Required="true" />
|
||
|
<Replace ParameterType="System.String" Required="true" />
|
||
|
<WarnOnNoMatch ParameterType="System.Boolean" Required="false" />
|
||
|
</ParameterGroup>
|
||
|
<Task>
|
||
|
<Using Namespace="System" />
|
||
|
<Using Namespace="System.IO" />
|
||
|
<Using Namespace="System.Text" />
|
||
|
<Using Namespace="System.Text.RegularExpressions" />
|
||
|
<Using Namespace="Microsoft.Build.Framework" />
|
||
|
<Using Namespace="Microsoft.Build.Utilities" />
|
||
|
<Code Type="Fragment" Language="cs">
|
||
|
<![CDATA[
|
||
|
try {
|
||
|
Regex regex = new Regex(Find, RegexOptions.Multiline | RegexOptions.Compiled);
|
||
|
|
||
|
foreach (ITaskItem file in Files) {
|
||
|
string fullPath = Path.GetFullPath(file.ItemSpec);
|
||
|
string originalText = File.ReadAllText(fullPath);
|
||
|
bool matched = regex.IsMatch(originalText);
|
||
|
|
||
|
if (!matched) {
|
||
|
if (WarnOnNoMatch) {
|
||
|
Log.LogWarning("No matches for '{0}' in '{1}'.", Find, fullPath);
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
File.SetAttributes(fullPath, File.GetAttributes(fullPath) & ~FileAttributes.ReadOnly);
|
||
|
File.WriteAllText(fullPath, regex.Replace(originalText, Replace), Encoding.UTF8);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
catch (Exception ex) {
|
||
|
Log.LogErrorFromException(ex);
|
||
|
return false;
|
||
|
}
|
||
|
]]>
|
||
|
</Code>
|
||
|
</Task>
|
||
|
</UsingTask>
|
||
|
</Project>
|