diff --git a/build.proj b/build.proj index 97bcabb6cb057..9de566ba5fb31 100644 --- a/build.proj +++ b/build.proj @@ -78,6 +78,7 @@ + @@ -297,7 +298,15 @@ - + + + + + + + + + diff --git a/tools/Microsoft.WindowsAzure.Build.Tasks/Build.Tasks.Tests/BuildTasksTest.BuildProjectTemplates.proj b/tools/Microsoft.WindowsAzure.Build.Tasks/Build.Tasks.Tests/BuildTasksTest.BuildProjectTemplates.proj new file mode 100644 index 0000000000000..c03f45b33cb06 --- /dev/null +++ b/tools/Microsoft.WindowsAzure.Build.Tasks/Build.Tasks.Tests/BuildTasksTest.BuildProjectTemplates.proj @@ -0,0 +1,43 @@ + + + + ..\..\..\ + $(LibraryRoot)tools + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/Microsoft.WindowsAzure.Build.Tasks/BuildProjectTemplatesTask.cs b/tools/Microsoft.WindowsAzure.Build.Tasks/BuildProjectTemplatesTask.cs new file mode 100644 index 0000000000000..8b5186416efaf --- /dev/null +++ b/tools/Microsoft.WindowsAzure.Build.Tasks/BuildProjectTemplatesTask.cs @@ -0,0 +1,90 @@ +/* + Copyright (c) Microsoft. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +namespace Microsoft.WindowsAzure.Build.Tasks +{ + using System; + using Microsoft.Build.Framework; + using Microsoft.Build.Utilities; + using NuGet; + using System.Collections.Generic; + using System.Linq; + using System.IO; + using System.IO.Compression; + + public class BuildProjectTemplatesTask : Task + { + /// + /// list of directories that contain template data + /// + IEnumerable TemplateDirList; + + /// + /// Directory path where the templates will be copied after build + /// + public string TemplateBuildOutputDirPath { get; set; } + + /// + /// True: If errors were detected during execution of task + /// False: If no errors were detected during task execution + /// + [Output] + public bool TaskErrorDetected { get; private set; } + + /// + /// Initialize data + /// + private void Init() + { + TaskErrorDetected = false; + TemplateDirList = new List { @"AutoRest-AzureDotNetSDK", @"AzureDotNetSDK-TestProject" }; + if (!Directory.Exists(TemplateBuildOutputDirPath)) + { + TemplateBuildOutputDirPath = Environment.GetEnvironmentVariable("Temp"); + } + } + + /// + /// Execute Build Template task + /// + /// + public override bool Execute() + { + try + { + Init(); + string projTemplateBaseDir = Path.Combine(Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).AbsolutePath), "projectTemplates"); + foreach (string templateDir in TemplateDirList) + { + string autoRestTemplateDir = Path.Combine(projTemplateBaseDir, templateDir); + string zipTemplateFile = Path.GetFullPath(Path.Combine(TemplateBuildOutputDirPath, string.Concat(templateDir, ".zip"))); + if (File.Exists(zipTemplateFile)) + { + File.Delete(zipTemplateFile); + } + + ZipFile.CreateFromDirectory(autoRestTemplateDir, zipTemplateFile); + Log.LogMessage("Successfully build and copied {0} template to '{1}'", templateDir, zipTemplateFile); + } + } + catch (Exception ex) + { + Log.LogErrorFromException(ex); + TaskErrorDetected = true; + } + return true; + } + } +} diff --git a/tools/Microsoft.WindowsAzure.Build.Tasks/DebugTask.cs b/tools/Microsoft.WindowsAzure.Build.Tasks/DebugTask.cs new file mode 100644 index 0000000000000..f7bf9332b5312 --- /dev/null +++ b/tools/Microsoft.WindowsAzure.Build.Tasks/DebugTask.cs @@ -0,0 +1,38 @@ +namespace Microsoft.Azure.Build.Tasks +{ + using Microsoft.Build.Utilities; + using System; + using ThreadTask = System.Threading.Tasks; + + + + /// + /// Utility task to help debug + /// + public class DebugTask : Microsoft.Build.Utilities.Task + { + /// + /// Default timeout + /// + const int DEFAULT_TASK_TIMEOUT = 20000; + + /// + /// Task Timeout + /// + public int Timeoutmiliseconds { get; set; } + + public override bool Execute() + { + if (Timeoutmiliseconds == 0) Timeoutmiliseconds = DEFAULT_TASK_TIMEOUT; + + ThreadTask.Task waitingTask = ThreadTask.Task.Run(() => + { + Console.WriteLine("Press any key to continue or it will continue in {0} seconds", (Timeoutmiliseconds / 1000)); + Console.ReadLine(); + }); + + waitingTask.Wait(TimeSpan.FromMilliseconds(Timeoutmiliseconds)); + return true; + } + } +} diff --git a/tools/Microsoft.WindowsAzure.Build.Tasks/Microsoft.WindowsAzure.Build.Tasks.csproj b/tools/Microsoft.WindowsAzure.Build.Tasks/Microsoft.WindowsAzure.Build.Tasks.csproj index 94746004f5346..1d9f0a0525a0f 100644 --- a/tools/Microsoft.WindowsAzure.Build.Tasks/Microsoft.WindowsAzure.Build.Tasks.csproj +++ b/tools/Microsoft.WindowsAzure.Build.Tasks/Microsoft.WindowsAzure.Build.Tasks.csproj @@ -9,8 +9,9 @@ Properties Microsoft.WindowsAzure.Build.Tasks Microsoft.WindowsAzure.Build.Tasks - v4.5 + v4.5.2 512 + true @@ -33,8 +34,16 @@ + + packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll + True + + + packages\NuGet.Core.2.12.0\lib\net40-Client\NuGet.Core.dll + + @@ -42,12 +51,18 @@ + + + + + +