Skip to content

Commit

Permalink
Port MSBuild targets from Korebuild into an SDK package
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate McMaster committed Jan 11, 2017
1 parent 9d32de7 commit efa9ff1
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 11 deletions.
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; EditorConfig to support per-solution formatting.
; Use the EditorConfig VS add-in to make this work.
; http://editorconfig.org/

; This is the default for the codeline.
root = true

[*]
indent_style = space
charset = utf-8
trim_trailing_whitespace = true

[*.{cs}]
indent_size = 4

; All XML-based file formats
[*.{config,csproj,nuspec,props,resx,targets,xml}]
indent_size = 2

[*.{json}]
indent_size = 2

[*.{ps1}]
indent_size = 4

[*.{sh}]
indent_size = 4
2 changes: 1 addition & 1 deletion NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
<clear />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
15 changes: 8 additions & 7 deletions build/common.props
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<Project>
<Import Project="..\version.props" />
<Import Project="..\.build\common.props" Condition="Exists('..\.build\common.props')" />

<PropertyGroup>
<!-- these imports substitute for a package reference to Internal.AspNetCore.Sdk -->
<_AspNetToolsSdkPath>$([MSBuild]::GetDirectoryNameOfFileAbove($(MsBuildThisFileDirectory), NuGet.config))\src\Internal.AspNetCore.Sdk</_AspNetToolsSdkPath>
<CustomBeforeMicrosoftCommonProps>$(_AspNetToolsSdkPath)\build\Internal.AspNetCore.Sdk.props</CustomBeforeMicrosoftCommonProps>
<CustomAfterMicrosoftCommonTargets>$(_AspNetToolsSdkPath)\build\Internal.AspNetCore.Sdk.targets</CustomAfterMicrosoftCommonTargets>
<CustomAfterMicrosoftCommonCrossTargetingTargets>$(_AspNetToolsSdkPath)\buildCrossTargeting\Internal.AspNetCore.Sdk.targets</CustomAfterMicrosoftCommonCrossTargetingTargets>
</PropertyGroup>

<PropertyGroup>
<RepositoryUrl>https://github.com/aspnet/BuildTools</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>

<Target Name="EnsureInitialized"
BeforeTargets="Build"
Condition="!Exists('$(MSBuildThisFileDirectory)..\.build\common.props')">
<Error File="$(MSBuildProjectFile)"
Text="Project has not been initialized. Run 'build initialize' in the solution directory." />
</Target>
</Project>
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "1.0.0-preview4-004233"
}
}
18 changes: 15 additions & 3 deletions makefile.shade
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@ var AUTHORS='Microsoft Open Technologies, Inc.'

default BASE_DIR='${Directory.GetCurrentDirectory()}'
default TARGET_DIR='${Path.Combine(BASE_DIR, "artifacts")}'
default BUILD_DIR='${Path.Combine(TARGET_DIR, "build")}'

use-standard-lifecycle
k-standard-goals

#xml-docs-test .clean .build-compile description='Check generated XML documentation files for errors' target='test'
k-xml-docs-test

#pack-sdk target='package'
@{
var buildNumber = E("BuildNumber") ?? BuildNumber;
NugetPack(E("KOREBUILD_NUGET_EXE") ?? ".build/NuGet.exe",
"src/Internal.AspNetCore.Sdk/Internal.AspNetCore.Sdk.nuspec",
BUILD_DIR,
"-Verbosity Detailed -Properties versionsuffix=alpha-" + buildNumber);
}

#nuget-pack target='package'
@{
var configuration = E("Configuration");
Expand All @@ -24,7 +34,6 @@ k-standard-goals
{ "SplitPackages", new [] { "net451" } },
};

var outputDir = Path.Combine(TARGET_DIR, "build");
var nugetPath = E("KOREBUILD_NUGET_EXE") ?? ".build/NuGet.exe";
var publishDir = Path.Combine(TARGET_DIR, "publish");

Expand All @@ -41,19 +50,22 @@ k-standard-goals
}

var nuspecPath = Path.Combine("src", projectName, projectName + ".nuspec");
var existingNupkg = Directory.EnumerateFiles(outputDir)
var existingNupkg = Directory.EnumerateFiles(BUILD_DIR)
.Select(p => Path.GetFileName(p))
.First(fn => fn.StartsWith(projectName) && fn.EndsWith(".nupkg"));
var version = Path.GetFileNameWithoutExtension(existingNupkg).Substring(projectName.Length + 1);

NugetPack(nugetPath,
nuspecPath,
outputDir,
BUILD_DIR,
version,
"-Verbosity Detailed -NoPack -BasePath \"" + basePath + "\""
+ " -Properties configuration=" + configuration);
}
}

macro name='NugetPack' nugetPath='string' nuspecFile='string' outputDir='string' extra='string'
nuget-pack

macro name='NugetPack' nugetPath='string' nuspecFile='string' outputDir='string' packageVersion='string' extra='string'
nuget-pack
13 changes: 13 additions & 0 deletions src/Internal.AspNetCore.Sdk/Internal.AspNetCore.Sdk.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>Internal.AspNetCore.Sdk</id>
<version>1.0.0-$versionsuffix$</version>
<authors>Microsoft</authors>
<description>Build targets and customizations to Microsoft.NET.Sdk</description>
<!-- TODO use contentFiles for cs files-->
</metadata>
<files>
<file src="**\*" target="/" />
</files>
</package>
4 changes: 4 additions & 0 deletions src/Internal.AspNetCore.Sdk/build/AssemblyInfo.Serviceable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

[assembly: System.Reflection.AssemblyMetadata("Serviceable", "True")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--
WARNING: These targets are intended for building Microsoft's ASP.NET Core repos, and is not intended
for use outside of Microsoft.
-->
<Project ToolsVersion="15.0">

<Import Project="$(MSBuildThisFileDirectory)..\targets\Common.props" Condition="'$(TargetFrameworks)'==''" />

</Project>
10 changes: 10 additions & 0 deletions src/Internal.AspNetCore.Sdk/build/Internal.AspNetCore.Sdk.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
WARNING: These targets are intended for building Microsoft's ASP.NET Core repos, and is not intended
for use outside of Microsoft.
-->
<Project ToolsVersion="15.0">

<Import Project="$(MSBuildThisFileDirectory)Workarounds.targets" />
<Import Project="$(MSBuildThisFileDirectory)..\targets\BuildNumber.targets" Condition="'$(TargetFrameworks)'==''" />

</Project>
50 changes: 50 additions & 0 deletions src/Internal.AspNetCore.Sdk/build/Workarounds.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!--
WARNING: These targets are intended for building Microsoft's ASP.NET Core repos, and is not intended
for use outside of Microsoft.
-->

<!-- this file is dedicated to working around bugs in Microsoft.NET.Sdk RC.2 release -->
<Project>
<!-- workaround https://github.com/Microsoft/vstest/issues/191 -->
<PropertyGroup
Condition="$(MSBuildProjectName.EndsWith('Test')) OR $(MSBuildProjectName.EndsWith('Tests'))">
<OutputType Condition="$(TargetFramework.StartsWith('netcoreapp'))">exe</OutputType>
</PropertyGroup>
<!-- end workaround -->

<!-- workaround https://github.com/NuGet/Home/issues/4063 -->
<!-- workaround https://github.com/NuGet/Home/issues/3953 -->
<Target Name="ResolveActualPackageVersions"
BeforeTargets="GenerateNuSpec"
DependsOnTargets="ResolvePackageDependenciesDesignTime">

<ItemGroup>
<_ProjectReferences Update="@(_ProjectReferences)" Condition="'%(PackageVersion)'==''">
<PackageVersion>$(Version)</PackageVersion>
</_ProjectReferences>

<_FloatingVersions Include="@(_PackageReferences)" Condition="$([System.String]::new('%(Version)').EndsWith('*'))" />
<_ResolvedFloatingVersion Include="@(_FloatingVersions)">
<ResolvedName>%(_DependenciesDesignTime.Name)</ResolvedName>
<Version>%(_DependenciesDesignTime.Version)</Version>
</_ResolvedFloatingVersion>
<_PackageReferences Remove="@(_PackageReferences)" Condition="$([System.String]::new('%(Version)').EndsWith('*'))" />
<_PackageReferences Include="@(_ResolvedFloatingVersion)" Condition="'%(Identity)'=='%(_ResolvedFloatingVersion.ResolvedName)'" />
</ItemGroup>

<Message Importance="Low" Text="Proj: %(_ProjectReferences.FileName) %(_ProjectReferences.PackageVersion)" />
<Message Importance="Low" Text="Pkg: %(_PackageReferences.Identity) %(_PackageReferences.Version)" />
</Target>
<!-- end workaround -->

<!-- workaround https://github.com/dotnet/sdk/issues/490 -->
<ItemGroup>
<!-- TODO use contentFiles in this package instead -->
<!-- checking DesignTimeBuild hides the file from from VS solution explorer which does not yet support 'Visible' -->
<!-- see https://github.com/dotnet/roslyn-project-system/issues/1126-->
<Compile Include="$(MSBuildThisFileDirectory)AssemblyInfo.Serviceable.cs"
Condition="'$(DesignTimeBuild)'!='true'"
Visible="false" />
</ItemGroup>
<!-- end workaround -->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--
WARNING: These targets are intended for building Microsoft's ASP.NET Core repos, and is not intended
for use outside of Microsoft.
-->
<Project ToolsVersion="15.0">

<Import Project="$(MSBuildThisFileDirectory)..\targets\Common.props" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!--
WARNING: These targets are intended for building Microsoft's ASP.NET Core repos, and is not intended
for use outside of Microsoft.
-->
<Project ToolsVersion="15.0">

<!-- TODO rename folder to buildMultiTargeting. See https://github.com/NuGet/Home/issues/4098 in RC.3 -->

<Import Project="$(MSBuildThisFileDirectory)Workarounds.targets" />
<Import Project="$(MSBuildThisFileDirectory)..\targets\BuildNumber.targets" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--
WARNING: These targets are intended for building Microsoft's ASP.NET Core repos, and is not intended
for use outside of Microsoft.
-->
<Project>
<!-- workaround https://github.com/NuGet/Home/issues/4063 -->
<!-- workaround https://github.com/NuGet/Home/issues/3953 -->
<Target Name="ResolveActualPackageVersions" BeforeTargets="GenerateNuspec">
<ItemGroup>
<_TargetFramework Include="$(TargetFrameworks)" />
</ItemGroup>

<MSBuild Projects="$(MSBuildProjectFile)"
Targets="ResolvePackageDependenciesDesignTime"
Properties="TargetFramework=%(_TargetFramework.Identity)">
<Output TaskParameter="TargetOutputs" ItemName="_DependenciesDesignTime" />
</MSBuild>

<ItemGroup>
<_ProjectReferences Update="@(_ProjectReferences)" Condition="'%(PackageVersion)'==''">
<PackageVersion>$(Version)</PackageVersion>
</_ProjectReferences>

<_FloatingVersions Include="@(_PackageReferences)" Condition="$([System.String]::new('%(Version)').EndsWith('*'))" />
<_ResolvedFloatingVersion Include="@(_FloatingVersions)">
<ResolvedName>%(_DependenciesDesignTime.Name)</ResolvedName>
<Version>%(_DependenciesDesignTime.Version)</Version>
</_ResolvedFloatingVersion>
<_PackageReferences Remove="@(_PackageReferences)" Condition="$([System.String]::new('%(Version)').EndsWith('*'))" />
<_PackageReferences Include="@(_ResolvedFloatingVersion)" Condition="'%(Identity)'=='%(_ResolvedFloatingVersion.ResolvedName)'" />
</ItemGroup>

<Message Importance="Low" Text="Proj: %(_ProjectReferences.FileName) %(_ProjectReferences.PackageVersion)" />
<Message Importance="Low" Text="Pkg: %(_PackageReferences.Identity) %(_PackageReferences.Version)" />
</Target>
<!-- end workaround -->
</Project>
31 changes: 31 additions & 0 deletions src/Internal.AspNetCore.Sdk/targets/BuildNumber.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
WARNING: These targets are intended for building Microsoft's ASP.NET Core repos, and is not intended
for use outside of Microsoft.
Usage: This file needs to be imported into the 'outer build'.
For multi-targeting projects, this will be imported from buildMultiTargeting/Internal.AspNetCore.Sdk.targets.
For single-tfm projects, this will be imported from build/Internal.AspNetCore.Sdk.targets.
-->
<Project ToolsVersion="15.0">
<!-- version options -->
<PropertyGroup>
<!--
Create second-based build number for local builds.
635556672000000000 is Jan 1, 2015.
-->
<_SecondBasedTimeStamp>$([System.DateTime]::UtcNow.Subtract($([System.DateTime]::FromBinary(635556672000000000))).TotalSeconds.ToString("F0"))</_SecondBasedTimeStamp>
<_SecondBasedTimeStamp>t$([System.Int64]::Parse($(_SecondBasedTimeStamp)).ToString("x9"))</_SecondBasedTimeStamp>

<!-- for aspnet CI -->
<!-- TODO can be removed when we retire project.json from all repos -->
<BuildNumber Condition="'$(BuildNumber)'==''">$(KOREBUILD_BUILD_NUMBER)</BuildNumber>

<!-- fallback build number if not set by KoreBuild-->
<BuildNumber Condition="'$(BuildNumber)'==''">$(_SecondBasedTimeStamp)</BuildNumber>
<VersionSuffix Condition="'$(VersionSuffix)'!='' AND '$(BuildNumber)' != ''">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
<VersionSuffix Condition="'$(VersionSuffix)'==''">$(BuildNumber)</VersionSuffix>
</PropertyGroup>

</Project>
27 changes: 27 additions & 0 deletions src/Internal.AspNetCore.Sdk/targets/Common.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
WARNING: These targets are intended for building Microsoft's ASP.NET Core repos, and is not intended
for use outside of Microsoft.
Usage: this should be imported once via NuGet at the top of the file.
-->
<Project ToolsVersion="15.0">

<!-- common package options -->
<PropertyGroup>
<NeutralLanguage Condition="'$(NeutralLanguage)'==''">en-US</NeutralLanguage>
<Company Condition="'$(Company)'==''">Microsoft Corporation.</Company>
<Authors Condition="'$(Authors)'==''">Microsoft</Authors>
<Copyright Condition="'$(Copyright)'==''">© Microsoft Corporation. All rights reserved.</Copyright>
<ProjectUrl Condition="'$(ProjectUrl)'==''">https://asp.net</ProjectUrl>
<RequireLicenseAcceptance Condition="'$(RequireLicenseAcceptance)'==''">true</RequireLicenseAcceptance>
<Serviceable Condition="'$(Configuration)' == 'Release' AND '$(Serviceable)'==''">true</Serviceable>
</PropertyGroup>

<!-- common build options -->
<PropertyGroup>
<!-- make disabling warnings opt-out -->
<WarningsAsErrors Condition="'$(WarningsAsErrors)'==''">true</WarningsAsErrors>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">

<Import Project="..\..\build\common.props" />

<PropertyGroup>
<VersionPrefix>1.0.1</VersionPrefix>
<TargetFrameworks>netcoreapp1.0;net451</TargetFrameworks>
<RuntimeIdentifier Condition=" '$(TargetFramework)'!='netcoreapp1.0' ">win7-x64</RuntimeIdentifier>
<Platform>AnyCPU</Platform>
<OutputType>exe</OutputType>
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ProjectModel" Version="1.0.0-rc3-003121" />
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.0.0" />
</ItemGroup>

</Project>

0 comments on commit efa9ff1

Please sign in to comment.