How and Why Do I Set Up a C# Build MAChine

How and why do I set up a C# build machine?

Update: Jenkins is the most up to date version of Hudson. Everyone should be using Jenkins now. I'll be updating the links accordingly.

Hudson is free and extremely easy to configure and will easily run on a VM.

Partly from an old post of mine:

We use it to

  • Deploy Windows services
  • Deploy web services
  • Run MSTests & display as much information as any junit tests
  • Keep track of low,med,high tasks
  • trendgraph warnings and errors

Here are some of the built in .net stuff that Hudson supports

  • MSBuild
  • NAnt
  • MSTest
  • Nunit
  • Team Foundation Server
  • fxcop
  • stylecop
  • compiler warnings
  • code tasks

Also, god forbid you are using visual source safe, it supports that as well. I'd recommend you take a look at Redsolo's article on building .net projects using Hudson

Your questions

  • Q: What kind of tools/licenses will I need? Right now, we use Visual Studio and Smart Assembly to build, and Perforce for source control. Will I need something else, or is there an equivalent of a cron job for running automated scripts?

  • A: I just installed visual studio on a fresh copy of a VM running a fresh, patched, install of a windows server OS. So you'd need the licenses to handle that. Hudson will install itself as a windows service and run on port 8080 and you will configure how often you want it to scan your code repository for updated code, or you can tell it to build at a certain time. All configurable through the browser.

  • Q: What, exactly, will this get me, other than an indication of a broken build? Should I set up test projects in this solution (sln file) that will be run by these scripts, so I can have particular functions tested? We have, at the moment, two such tests, because we haven't had the time (or frankly, the experience) to make good unit tests.

    A: You will get an email on the first time a build fails, or becomes unstable. A build is unstable if a unit test fails or it can be marked unstable through any number of criteria that you set. When a unit test or build fails you will be emailed and it will tell you where, why and how it failed. With my configuration, we get:

    • list of all commits since the last working build
    • commit notes of those commits
    • list of files changed in the commits
    • console output from the build itself, showing the error or test failure
  • Q: What kind of hardware will I need for this?

    A: A VM will suffice

  • Q: Once a build has been finished and tested, is it a common practice to put that build up on an ftp site or have some other way for internal access? The idea is that this machine makes the build, and we all go to it, but can make debug builds if we have to.

    A: Hudson can do whatever you want with it, that includes ID'ing it via the md5 hash, uploading it, copying it, archiving it, etc. It does this automatically and provides you with a long running history of build artifacts.

  • Q: How often should we make this kind of build?

    A: We have ours poll SVN every hour, looking for code changes, then running a build. Nightly is ok, but somewhat worthless IMO since what you've worked on yesterday wont be fresh in your mind in the morning when you get in.

  • Q: How is space managed? If we make nightly builds, should we keep around all the old builds, or start to ditch them after about a week or so?

    A: Thats up to you, after so long I move our build artifacts to long term storage or delete them, but all the data which is stored in text files / xml files I keep around, this lets me store the changelog, trend graphs, etc on the server with verrrry little space consumed. Also you can set Hudson up to only keep artifacts from a trailing # of builds

  • Q: Is there anything else I'm not seeing here?

    A: No, Go get Hudson right now, you wont be disappointed!

Setting up a Build machine with TeamCity

Installing .NET and the Windows SDK (the .NET parts) should be sufficient. Depending on the project types you are using, it will be necessary to copy build targets from your local machine to the build agents (but this is a one time configuration).

can I run C# built-in unit test in build machine?

MSTest.exe MSTest.exe Command-Line Options or maybe gallio

Make an Installation program for C# applications and include .NET Framework installer into the setup

Use Visual Studio Setup project. Setup project can automatically include .NET framework setup in your installation package:

Here is my step-by-step for windows forms application:

  1. Create setup project. You can use Setup Wizard.

    Sample Image

  2. Select project type.

    Sample Image

  3. Select output.

    Sample Image

  4. Hit Finish.

  5. Open setup project properties.

    Sample Image

  6. Chose to include .NET framework.

    Sample Image

  7. Build setup project

  8. Check output

    Sample Image


Note: The Visual Studio Installer projects are no longer pre-packed with Visual Studio. However, in Visual Studio 2013 you can download them by using:

Tools > Extensions and Updates > Online (search) > Visual Studio Installer Projects

How can I compile and run c# program without using visual studio?

If you have .NET v4 installed (so if you have a newer windows or if you apply the windows updates)

C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe somefile.cs

or

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe nomefile.sln

or

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe nomefile.csproj

It's highly probable that if you have .NET installed, the %FrameworkDir% variable is set, so:

%FrameworkDir%\v4.0.30319\csc.exe ...

%FrameworkDir%\v4.0.30319\msbuild.exe ...

How to compile c# in Microsoft's new Visual Studio Code?

Intellisense does work for C# 6, and it's great.

For running console apps you should set up some additional tools:

  • ASP.NET 5; in Powershell: &{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
  • Node.js including package manager npm.
  • The rest of required tools including Yeoman yo: npm install -g yo grunt-cli generator-aspnet bower
  • You should also invoke .NET Version Manager: c:\Users\Username\.dnx\bin\dnvm.cmd upgrade -u

Then you can use yo as wizard for Console Application: yo aspnet Choose name and project type. After that go to created folder cd ./MyNewConsoleApp/ and run dnu restore

To execute your program just type >run in Command Palette (Ctrl+Shift+P), or execute dnx . run in shell from the directory of your project.

How to compile .NET Core app for Linux on a Windows machine

Using dotnet build command, you may specify --runtime flag

-r|--runtime < RUNTIME_IDENTIFIER >

Target runtime to build for. For a list of Runtime Identifiers (RIDs) you can use, see the RID catalog.

RIDs that represent concrete operating systems usually follow this pattern [os].[version]-[arch]

Fo example, to build a project and its dependencies for Ubuntu 16.04 runtime use:

dotnet build --runtime ubuntu.16.04-x64


Related Topics



Leave a reply



Submit