Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port MSBuild targets from Korebuild into an SDK package #145

Merged
merged 1 commit into from
Jan 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

; 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global.json in an msbuild project?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. global.json also used by the dotnet.exe muxer to determine SDK version.

}
}
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra space

"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-->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This work item is tracked somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's part of aspnet/KoreBuild#150

</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")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? There's not supposed to be a DLL in this project, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not .dll for the SDK. This file is added to the <Compile> items.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed? Oh wait, is this for all our regular projects to consume (i.e. we can delete this from all the other repos)? Or is this actually compiled into a DLL right here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. This is for regular projects. we started deleting AssemblyInfo.cs from our projects because all of its content is generated by Microsoft.NET.SDK (with the exception of the this serviceable attrbute).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an RC3 build we could use that addresses these workarounds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. We're still stuck on RC.2 because of blocking issues.

<!-- 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' -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a tracking work item for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<!-- 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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does <_Timestamp>$([System.DateTime]::UtcNow.Ticks.ToString("x").PadLeft(20, '0')</_Timestamp> work? I know they removed the special version length restriction in recent builds of NuGet, so we could simplify this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might work. But I still prefer the shorter version.

Plus, it's possible some might build with NuGet 4.0 but need to install to project.json which uses NuGet 3.5. I'm not confident the version-length restriction is fixed there.

<_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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just modify the CI to specify /p:BuildNumber=%build.number% and remove references to KoreBuild here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too early. We can do this when we migrate everything to MSbuild.


<!-- 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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we care about Configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want debug nupkgs to be marked as serviceable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really doesn't matter. Those don't get built \ published on the CI

</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">

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo?

<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>