Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Build with MSBuild #238

Merged
merged 1 commit into from Dec 12, 2016
Merged

Build with MSBuild #238

merged 1 commit into from Dec 12, 2016

Conversation

natemcmaster
Copy link
Contributor

@natemcmaster natemcmaster commented Nov 24, 2016

Please take a look. The migration of project.json to csproj is mostly done. The shared infrastructure around it needs work (e.g. KoreBuild's replacement).

Resolves #179

cc @bricelam


<Target Name="Test">
<MSBuild Targets="VSTest"
Projects="@(TestProjects)" />

Choose a reason for hiding this comment

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

I think this will run test assemblies in parallel. You may want to use task batching (i.e. Projects="%(TestProjects.Identity)") to prevent this.

Copy link

@bricelam bricelam Nov 29, 2016

Choose a reason for hiding this comment

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

Oh, I lied. BuildInParallel defaults to false. But in that case, you may want to consider adding it wherever you use the MSBuild task with multiple projects. It does a topological sort (based on ProjectReference items) and builds the parts in can in parallel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Would be good if it works well. I'll play it. Not sure how well VSTest handles parallel test projects.

Choose a reason for hiding this comment

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

I don't think we should test in parallel. Just build/pack.

</PropertyGroup>
<ItemGroup>
<SourceProjects Include="src\*\*.csproj" />
<TestProjects Include="test\*\*.csproj" />

Choose a reason for hiding this comment

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

I've always wanted the unit tests to run before functional/integration/end-to-end tests... It seems like a good way to "fail fast".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be awesome. My MSBuild-ese isn't quite good enough to know the best way to code a good sorting algorithm like that....does the .NET Core MSBuild support code tasks?

Choose a reason for hiding this comment

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

does the .NET Core MSBuild support code tasks

Not last I checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😢

Choose a reason for hiding this comment

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

I'd just do it in two passes.

<ItemGroup>
  <UnitTestProject Include="test/**/*.Test.csproj" />
  <OtherTestProject Include="test/**/*.csproj" Exclude="@(UnitTestProject)" />
</ItemGroup>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's easier. added it.

throw 'Restoring packages for build.xml failed'
}
& $env:DOTNET_HOME/dotnet.exe msbuild build.xml /nologo /v:m $args

Choose a reason for hiding this comment

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

Add /m for a bit more oomph.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooh, nice. Yeah, let's put that CPU to work

<Target Name="Pack">
<MSBuild Targets="Rebuild;Pack"
Projects="@(SourceProjects)"
Properties="PackageOutputPath=$(ArtifactsPath)" />

Choose a reason for hiding this comment

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

May also want to flow Configuration=$(Configuration)

Choose a reason for hiding this comment

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

(On other MSBuild usages too.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So i'm still a little fuzzy on how properties flow form outer to inner builds, but I thought properties like Configuration just automatically flow into inner builds unless explicitly listed in 'RemoveProperties'...

Copy link

@bricelam bricelam Nov 29, 2016

Choose a reason for hiding this comment

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

Calling the MSBuild task creates a new context/scope--no properties are preserved unless you pass them here.

Choose a reason for hiding this comment

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

AFAIK, the RemoveProperties is used to remove properties specified in the Projects items' Properties and AdditionalProperties metadata.

Copy link

@bricelam bricelam Nov 29, 2016

Choose a reason for hiding this comment

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

<ItemDefinitionGroup>
  <Project>
    <AdditionalProperties>C=C</AdditionalProperties>
  </Project>
</ItemDefinitionGroup>

<ItemGroup>
  <Project Include="SomeProject">
    <Properties>A=A;B=B</Properties>
  </Project>
</ItemGroup>

<!-- Flow B, C & D, but not A -->
<MSBuild Projects="@(Project)" RemoveProperties="A" Properties="D=D" />

Choose a reason for hiding this comment

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

I ❤️ MSBuild. (In a Stockholm syndrome kind of way)

</Target>

<Target Name="Pack">
<MSBuild Targets="Rebuild;Pack"

Choose a reason for hiding this comment

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

Why force a full rebuild every time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Will remove.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<Import Project="..\..\build\common.props" />
Copy link
Member

Choose a reason for hiding this comment

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

..........

Copy link
Member

Choose a reason for hiding this comment

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

Remind me, by default this is relative to the project file right? I still think this should be a package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

by default this is relative to the project file right?

Yes.

I still think this should be a package.

Agreed. As per ongoing discussion in https://github.com/aspnet/specs/pull/49, I fully intend to move most of these common properties to a package. When that happens, we can remove duplication from that file. That said, there is still a high chance we will still want a common.props file per repo for settings that truly are repo specific, such as RepositoryUrl.

Choose a reason for hiding this comment

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

this is relative to the project file right

Yes, the project you pass to msbuild, and you use $(MSBuildThisFileDirectory) to reference files relative to the current one.

<!--<PackageReference Include="Microsoft.Extensions.Process.Sources" Version="1.1.0-*" PrivateAssets="All" />-->

<!-- ExcludeAssets="build" to workaround https://github.com/dotnet/corefx/issues/12913 -->
<PackageReference Include="Microsoft.DiaSymReader.Native" Version="1.4.0" ExcludeAssets="build" PrivateAssets="All" />
Copy link
Member

Choose a reason for hiding this comment

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

What is this for?

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 was a workaround for dotnet/roslyn#15137. Just checked again and the workaround can be removed now.

@natemcmaster
Copy link
Contributor Author

⌚ Putting this work on hold. Found some un-workaround-able issues.

microsoft/vstest#241 - dotnet test returns exit code 0 even when tests fail
microsoft/vstest#254 - VSTest breaks TeamCity test reporting

@natemcmaster natemcmaster force-pushed the namc/build-with-msbuild branch 2 times, most recently from 1e99fc1 to e71a8f2 Compare December 8, 2016 19:02
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGetPackageVerifier" Version="1.0.1-*" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Version 1.0.2-*?

@natemcmaster natemcmaster force-pushed the namc/build-with-msbuild branch 2 times, most recently from a5abd62 to 180586c Compare December 12, 2016 21:19
@natemcmaster
Copy link
Contributor Author

🆙 📅 Changing course. Sticking with KoreBuild for now to simplify our conversion process.

Removing wip: label. This PR is ready.

cc @prafullbhosale can you take a look?

@natemcmaster natemcmaster changed the title wip: Build with MSBuild Build with MSBuild Dec 12, 2016
Copy link
Contributor

@prafullbhosale prafullbhosale left a comment

Choose a reason for hiding this comment

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

Looks mostly good.

</PropertyGroup>

<PropertyGroup Condition="$(PackWithoutBuildNumber)">
<PackageVersion>$(VersionPrefix)</PackageVersion>
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this being set in case PackWithoutBuildNumber == false? or does it not need to be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this repo, version.props has it...but you make a good point. This should be made safer so that it can be generalized.

Copy link
Contributor

Choose a reason for hiding this comment

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

version.props only sets the VersionPrefix and VersionSuffix but not the PackageVersion.
Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, PackageVersion is in NuGet's pack targets. It defaults to $(Version) but can be overridden if you want the pkg version to differ from the build version.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Did not know that.

<PackageType>DotnetCliTool</PackageType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.0" />
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would rather have this package reference included in every csproj to be explicit.

@@ -2,10 +2,5 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Reflection;
using System.Resources;

[assembly: AssemblyMetadata("Serviceable", "True")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still required? This seems to be set in the pack options in common.props

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, still required. This is different from the serviceable tag on the nupkg.

@natemcmaster natemcmaster merged commit 902ff8d into feature/msbuild Dec 12, 2016
@natemcmaster natemcmaster deleted the namc/build-with-msbuild branch December 12, 2016 23:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants