Skip to content

Commit

Permalink
Removed pre-built templates. Added project build task, added targets …
Browse files Browse the repository at this point in the history
…to build.proj, updated Repo-Tasks to build and install VS Project templates. Added tests to buildProjectTask. Updated project template to use latest Client Runtime
  • Loading branch information
shahabhijeet committed Nov 3, 2016
1 parent 665d487 commit ace6ed0
Show file tree
Hide file tree
Showing 23 changed files with 496 additions and 12 deletions.
11 changes: 10 additions & 1 deletion build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

<UsingTask TaskName="ValidateStrongNameSignatureTask" AssemblyFile="$(LibraryToolsFolder)\Microsoft.WindowsAzure.Build.Tasks.dll" />
<UsingTask TaskName="FilterOutAutoRestLibraries" AssemblyFile="$(LibraryToolsFolder)\Microsoft.WindowsAzure.Build.Tasks.dll" />
<UsingTask TaskName="BuildProjectTemplatesTask" AssemblyFile="$(LibraryToolsFolder)\Microsoft.WindowsAzure.Build.Tasks.dll" />

<!-- Building ClientRuntime projects -->
<Target Name="BuildClientRuntime">
Expand Down Expand Up @@ -297,7 +298,15 @@
<Exec Command="$(NuGetCommand) restore %(NonAutoRestLibraries.Identity) $(NuGetRestoreConfigSwitch)" Condition=" @(NonAutoRestLibraries) != '' "/>
<Exec Command="$(NuGetCommand) install xunit.runner.console -Version 2.0.0 -o $(LibraryNugetPackageFolder)" />
</Target>


<!-- Task to build project templates -->
<Target Name="BuildProjectTemplates">
<Message Text="Building Project Templates" />
<BuildProjectTemplatesTask>
<Output TaskParameter="TaskErrorDetected" PropertyName="BuildTemplateTaskFailed" />
</BuildProjectTemplatesTask>
<Message Text="Building Project Templates Completed" />
</Target>
<!--
We have some important work to do when building our official Library bits.
-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="RunTest" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LibraryRoot>..\..\..\</LibraryRoot>
<LibraryToolsFolder>$(LibraryRoot)tools</LibraryToolsFolder>
</PropertyGroup>
<UsingTask TaskName="BuildProjectTemplatesTask" AssemblyFile="$(LibraryToolsFolder)\Microsoft.WindowsAzure.Build.Tasks.dll" />
<UsingTask TaskName="DebugTask" AssemblyFile="$(LibraryToolsFolder)\Microsoft.WindowsAzure.Build.Tasks.dll" />

<Target Name="BuildTemplate">
<Message Text="Executing Test 'BuildTemplate'" />
<BuildProjectTemplatesTask>
<Output TaskParameter="TaskErrorDetected" PropertyName="BuildTemplateTaskFailed" />
</BuildProjectTemplatesTask>
<Message Condition="'$(BuildTemplateTaskFailed)' == 'false'" Text="Test Passed !!!!!!!!!!"/>
<Message Condition="'$(BuildTemplateTaskFailed)' == 'true'" Text="!!!!!!!!!! Not expecting errors Test Failed !!!!!!!!!!"/>
<Message Text="'BuildTemplate' finished executing" />
</Target>

<Target Name="BT_InvalidOutputDir">
<Message Text="Executing Test 'BT_InvalidOutputDir'" />
<BuildProjectTemplatesTask TemplateBuildOutputDirPath="C:\nonExistingDir">
<Output TaskParameter="TaskErrorDetected" PropertyName="BuildTemplateTaskFailed" />
</BuildProjectTemplatesTask>
<Message Condition="'$(BuildTemplateTaskFailed)' == 'false'" Text="Test Passed !!!!!!!!!!"/>
<Message Condition="'$(BuildTemplateTaskFailed)' == 'true'" Text="!!!!!!!!!! Not expecting errors Test Failed !!!!!!!!!!"/>
<Message Text="'BT_InvalidOutputDir' finished executing" />
</Target>

<Target Name="BT_OutputDirNeedAdminRights">
<Message Text="Executing Test 'BT_OutputDirNeedAdminRights'" />
<BuildProjectTemplatesTask TemplateBuildOutputDirPath="$(ProgramFiles)" ContinueOnError="true">
<Output TaskParameter="TaskErrorDetected" PropertyName="BuildTemplateTaskFailed" />
</BuildProjectTemplatesTask>
<Message Condition="'$(BuildTemplateTaskFailed)' == 'true'" Text="Expecting Errors, Test Passed !!!!!!!!!!"/>
<Message Condition="'$(BuildTemplateTaskFailed)' == 'false'" Text="!!!!!!!!!! No Errors detected, this is unexpected Test Failed !!!!!!!!!!"/>
<Message Text="'BT_OutputDirNeedAdminRights' finished executing" />
</Target>

<Target Name="RunTest" DependsOnTargets="BuildTemplate;BT_InvalidOutputDir;BT_OutputDirNeedAdminRights">
<Message Text="Test Suite completed"/>
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// list of directories that contain template data
/// </summary>
IEnumerable<string> TemplateDirList;

/// <summary>
/// Directory path where the templates will be copied after build
/// </summary>
public string TemplateBuildOutputDirPath { get; set; }

/// <summary>
/// True: If errors were detected during execution of task
/// False: If no errors were detected during task execution
/// </summary>
[Output]
public bool TaskErrorDetected { get; private set; }

/// <summary>
/// Initialize data
/// </summary>
private void Init()
{
TaskErrorDetected = false;
TemplateDirList = new List<string> { @"AutoRest-AzureDotNetSDK", @"AzureDotNetSDK-TestProject" };
if (!Directory.Exists(TemplateBuildOutputDirPath))
{
TemplateBuildOutputDirPath = Environment.GetEnvironmentVariable("Temp");
}
}

/// <summary>
/// Execute Build Template task
/// </summary>
/// <returns></returns>
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;
}
}
}
38 changes: 38 additions & 0 deletions tools/Microsoft.WindowsAzure.Build.Tasks/DebugTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Microsoft.Azure.Build.Tasks
{
using Microsoft.Build.Utilities;
using System;
using ThreadTask = System.Threading.Tasks;



/// <summary>
/// Utility task to help debug
/// </summary>
public class DebugTask : Microsoft.Build.Utilities.Task
{
/// <summary>
/// Default timeout
/// </summary>
const int DEFAULT_TASK_TIMEOUT = 20000;

/// <summary>
/// Task Timeout
/// </summary>
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.WindowsAzure.Build.Tasks</RootNamespace>
<AssemblyName>Microsoft.WindowsAzure.Build.Tasks</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -33,21 +34,35 @@
<ItemGroup>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Reference Include="Microsoft.Web.XmlTransform, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NuGet.Core">
<HintPath>packages\NuGet.Core.2.12.0\lib\net40-Client\NuGet.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BuildProjectTemplatesTask.cs" />
<Compile Include="DebugTask.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="FilterOutAutoRestLibraries.cs" />
<Compile Include="RegexReplacementTask.cs" />
<Compile Include="StrongNameUtility.cs" />
<Compile Include="ValidateStrongNameSignatureTask.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Build.Tasks.Tests\BuildTasksTest.BuildProjectTemplates.proj" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
5 changes: 5 additions & 0 deletions tools/Microsoft.WindowsAzure.Build.Tasks/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net45" />
<package id="NuGet.Core" version="2.12.0" targetFramework="net45" />
</packages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>$guid1$</ProjectGuid>
<RootNamespace>$safeprojectname$</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>AutoRest-AzureDotNetSDK</Name>
<Description>AutoRest generated project template for Azure .NET SDK</Description>
<ProjectType>DNX</ProjectType>
<ProjectSubType>
</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<CreateInPlace>true</CreateInPlace>
<DefaultName>AutoRest-AzureDotNetSDK</DefaultName>
<CreateInPlace>true</CreateInPlace>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<Project TargetFileName="AutoRest-AzureDotNetSDK.xproj" File="AutoRest-AzureDotNetSDK.xproj" ReplaceParameters="true">
<Folder Name="Properties" TargetFolderName="Properties">
<ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
</Folder>
<Folder Name="Generated" TargetFolderName="Generated">
<Folder Name="Models" TargetFolderName="Models" />
</Folder>
<ProjectItem ReplaceParameters="false" TargetFileName="MSSharedLibKey.snk">MSSharedLibKey.snk</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="project.json">project.json</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="project.lock.json">project.lock.json</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Readme.txt" OpenInEditor="true">Readme.txt</ProjectItem>
</Project>
</TemplateContent>
</VSTemplate>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System;
using System.Resources;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("$safeprojectname$")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]




30 changes: 30 additions & 0 deletions tools/ProjectTemplates/AutoRest-AzureDotNetSDK/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Changing Package Name
======================
Project directory name becomes package name by default.
If you would like change the package name of the project do the following
1) Rename the project directory to the desired name. project directory = name of the directory where project.json is located
2) Make the appropriate changes for the AssemblyProduct attribute defined in AssemblyInfo.cs

Adding code generated from AutoRest
===================================
1) Add the generated code to the existing Generated directory that you see in the project template

Adding test project to test your newly added SDK project
========================================================
1) Click Add new project to the existing solution
2) Search for "AzureDotNetSDK-TestProject"
3) Give appropriate name of your new Test Project, choose the right location

References:
===========
If you are adding a new reference, all three targets (.NET45, .NET standard 1.1, .NET standard 1.5) will need to be supported
So add the appropriate reference in project.json for the all the 3 frameworks that are listed in project.json

For more information please visit
https://github.com/Azure/adx-documentation-pr/blob/master/README.md

If you do not have access to the above repository, please visit
http://aka.ms/azuregithub

And join Azure Organization
https://repos.opensource.microsoft.com/Azure/
Binary file not shown.
Loading

0 comments on commit ace6ed0

Please sign in to comment.