Skip to content

Commit

Permalink
Simplify the build process & scripts (#648)
Browse files Browse the repository at this point in the history
* Remove old debris

Apparently, the build script used to compute code coverage, but this
has been disabled for a long time and would probably take some work to
bring up-to-date again. Let's remove this for now and add it back once
we have cleaned up the build process.

SourceLink verification has been disabled because it doesn't work well
while one is working locally. Let's remove it and bring it back once
we have cleaned up the build process.

The CI server (AppVeyor) is set up to push packages to NuGet, and this
is how packages should be published. Most users of this build script
wouldn't be able to use `Publish` anyway because they do not know the
NuGet API key required for pushing. So, remove this target lest people
think that they *should* be able to use it.

Also, remove obsolete entries from `.gitignore`.

* Separate project for AppVeyor build version update

... which we trigger from `appveyor.yml`.

While we're at it, change the format used for AppVeyor build versions
to use something a little more unique. The version scheme used so far
frequently caused version collisions (and unnecessary build warnings)
e.g. when force-pushing changed commits on a PR branch.

* Delegate `Test` target to test projects

Currently, `build.proj` restores xUnit-related packages which is not
actually necessary, since the unit test projects already require them.
Moving the responsibility of running tests to the test projects them-
selves makes this much clearer and means that the build script won't
have to do redundant work.

* Use `Pack` target instead of `nuget pack`

* Use MSBuild-integrated package restore

This finally makes an external `nuget` tool obsolete, which lets us
remove a ton of build script stuff.

* Extract basic assembly info into shared `AssemblyInfo.props`

* Extract GitInfo build parts into `GitVersion.props`

* Extract SourceLink build parts into `SourceLink.props`

(The reason why we're specifying that SourceLink should not run if
building from inside Visual Studio is that SourceLink produces some
garbled output in the 'Output' window there that cannot be easily
suppressed.)

* Extract xUnit build parts into `xUnit.props`

* Extract strong-naming build parts into `SignAssembly.props`

* Replace `dotnet xunit` with `dotnet test`, then upgrade to xUnit 2.4

xUnit 2.4 has abandoned the `dotnet-xunit` CLI tool which we rely on
to run our unit tests. We cannot keep using `dotnet-xunit` if we want
to be able to upgrade xUnit, so let's get rid of it now.

Alternatives considered:

 * `xunit.runner.msbuild` would seem like the obvious choice, but it
   is not cross-platform since it only targets .NET 4.5.

 * `xunit.runner.console` would be the next best thing, since it is
   as feature-complete as `dotnet-xunit` (e.g. it can generate HTML
   and XML test run reports and knows about options like `-noshadow`)
   but it's excruciatingly hard to call, since it comes in various
   versions and we need to map the current `<TargetFramework>` to an
   appropriate command line. Unfortunately, MSBuild multi-targeting
   does not work automatically for `<TargetFrameworks>` and we'd need
   to perform some MSBuild contorsions / recursion to get there.

 * `dotnet test` works well with multi-targeting, but doesn't have all
   options that we've used up until now.

Let's go with the last one for simplicity's sake. If we get complaints
about missing test run report files, we can go back to the more stren-
uous `xunit.runner.console`.

* Remove `build.cmd` and `build.proj`

We have got `build.proj` to a point where it does only few things:

 1. sets default build targets via `<Project @DefaultTargets>`
 2. invokes MSBuild on the solution or projects for each target
 3. creates and deletes the `out/` directory
 4. specifies the dependencies between the targets

All of these except (1) can be done without a dedicated build project,
and (1) isn't crucial since we can just set the build targets e.g. in
`appveyor.yml`. For command line execution, the MSBuild default target
`Build` will often be good enough.

* Normalize whitespace to tabs

* Add CoreBuild Standard badge to README
  • Loading branch information
stakx authored Jul 27, 2018
1 parent 20221fe commit dfcbd51
Show file tree
Hide file tree
Showing 23 changed files with 169 additions and 386 deletions.
8 changes: 4 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ end_of_line = CRLF
indent_style = tab
indent_size = 4

[*.{sln,proj,props,targets,xml,config,nuspec}]
[*.{sln,proj,csproj,vbproj,props,targets,xml,xdoc,resx,config,nuspec}]
indent_style = tab
indent_size = 4
indent_size = 2

[*.{csproj,resx}]
[appveyor.yml]
indent_style = space
indent_size = 2
indent_size = 2
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
.nuget
out
build
bin
obj
lib
packages
*.nuget.targets
*.nuget.props
*.lock.json
*.suo
*.user
*.cache
.vs
.*
log.txt
9 changes: 6 additions & 3 deletions Before.Moq.sln.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Project>

<Import Project="NuGet.Restore.targets" />
<Import Project="Directory.Build.props" />

<Target Name="DeleteOutputDirectory" AfterTargets="Clean">
<RemoveDir Directories="$(OutputDirectory)" Condition="Exists('$(OutputDirectory)')" />
</Target>

</Project>
12 changes: 12 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>

<PropertyGroup>
<RootDirectory>$(MSBuildThisFileDirectory)</RootDirectory>
<BuildDirectory>$(RootDirectory)build\</BuildDirectory>
<OutputDirectory>$(RootDirectory)out\</OutputDirectory>
<Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
</PropertyGroup>

<Target Name="Configure" DependsOnTargets="Restore" />

</Project>
4 changes: 1 addition & 3 deletions Moq.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A5A5B8C3-D43F-43C6-AEC7-6FA7C35B8BE9}"
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
build.proj = build.proj
CHANGELOG.md = CHANGELOG.md
GitInfo.txt = GitInfo.txt
License.txt = License.txt
Moq.nuspec = Moq.nuspec
packages.config = packages.config
src\Moq\Moq.nuspec = src\Moq\Moq.nuspec
README.md = README.md
EndProjectSection
EndProject
Expand Down
91 changes: 0 additions & 91 deletions NuGet.Restore.targets

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The most popular and friendly mocking framework for .NET
[![Version](https://img.shields.io/nuget/v/Moq.svg)](https://www.nuget.org/packages/Moq)
[![Downloads](https://img.shields.io/nuget/dt/Moq.svg)](https://www.nuget.org/packages/Moq)
[![Join the chat at https://gitter.im/moq/moq](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/moq/moq?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![CoreBuild Standard](https://img.shields.io/badge/√_corebuild-standard-blue.svg)](http://www.corebuild.io)


```csharp
Expand Down
8 changes: 5 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ image: Visual Studio 2017
init:
- git config --global core.autocrlf input

environment:
MSBUILD_LOGGER: C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll

build_script:
- cmd: >-
build.cmd /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
- msbuild build\AppVeyor.proj /r /t:UpdateBuildVersion /logger:"%MSBUILD_LOGGER%"
- msbuild Moq.sln /r /t:Build;Test;Pack /logger:"%MSBUILD_LOGGER%"

# we run the tests ourselves in build.cmd for coverage
test: off

deploy:
Expand Down
42 changes: 0 additions & 42 deletions build.cmd

This file was deleted.

121 changes: 0 additions & 121 deletions build.proj

This file was deleted.

19 changes: 19 additions & 0 deletions build/AppVeyor.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.Build.NoTargets/1.0.39">

<Import Project="$(BuildDirectory)GitVersion.props" />

<PropertyGroup>
<TargetFramework>netstandard1.0</TargetFramework>
</PropertyGroup>

<Target Name="UpdateBuildVersion" DependsOnTargets="GitVersion">
<PropertyGroup>
<BuildVersion>$(GitBaseVersion)</BuildVersion>
<BuildVersion Condition="'$(GitCommits)' != '0'">$(BuildVersion).$(GitCommits)</BuildVersion>
<BuildVersion>$(BuildVersion)+sha.$(GitCommit)</BuildVersion>
</PropertyGroup>
<Exec Command="appveyor UpdateBuild -Version $(BuildVersion)"
ContinueOnError="WarnAndContinue" />
</Target>

</Project>
11 changes: 11 additions & 0 deletions build/AssemblyInfo.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<GenerateAssemblyInfo Condition="'$(GenerateAssemblyInfo)' == ''">True</GenerateAssemblyInfo>
<AssemblyTitle Condition="'$(AssemblyTitle)' == ''">$(MSBuildProjectName)</AssemblyTitle>
<Product Condition="'$(Product)' == ''">Moq</Product>
<Company Condition="'$(Company)' == ''">Clarius Consulting, Manas Technology Solutions, InSTEDD</Company>
</PropertyGroup>

</Project>
Loading

0 comments on commit dfcbd51

Please sign in to comment.