KB 600005 How to compile source code on Windows

Summary

This article describes how to compile #SNMP source code on Windows.

Prerequisites

You may check out the source code using Git, from https://github.com/lextm/sharpsnmplib or download the ZIP package from the GitHub page.

Default Configuration

#SNMP has several projects. Most of them are configured to compile against .NET Framework 3.5 except SharpSnmpLib.csproj who is against .NET Framework 2.0.

If you have .NET Framework 3.5 installed

.NET Framework 3.5 SP1 is available here.
  1. Install .NET SDK or Visual Studio.
  2. Execute prepare.bat to prepare necessary files.
  3. Execute release.35.bat to build the source code.
The compiled binaries are in the bin folder. They are built using MSBuild 3.5. Core assemblies are against .NET 2.0 SP2, while others against .NET 3.5 SP1.

If you have .NET Framework 4.0 installed

.NET Framework 4.0 installer is available here.
  1. Install .NET SDK or Visual Studio.
  2. Execute prepare.bat to prepare necessary files.
  3. Execute release.bat to build the source code.
The compiled binaries are in the bin folder. They are built using MSBuild 4.0. Core assemblies are against .NET 2.0 SP2, while others against .NET 3.5 SP1.

More Information

#SNMP is supported on Windows XP (SP3), Windows Vista (SP2), Windows 7, Windows Server 2003 (SP2), Windows Server 2008 (SP2), and Windows Server 2008 R2.

WinForms applications are not recommended to be edited in Visual Studio 2008. Please switch to Visual Studio 2010 (including Visual C# 2010).

Compile #SNMP Against .NET Framework 4.0

You must have .NET Framework 4.0 installed.
  1. Open a Visual Studio 2010 command prompt and navigate to the folder that contains sharpsnmplib.sln.
  2. Execute "msbuild sharpsnmplib.sln /p:TargetFrameworkVersion=v4.0"

All resulting assemblies are linked against .NET 4 version of mscorlib.dll, and so on.

.NET 4

References

N/A

Last edited Jan 27, 2012 at 3:56 AM by lextm, version 5

Comments

lextm Dec 15, 2012 at 8:10 AM 
The stg issue was found after ANTLR 3.4.1 C# was out, so we will have to wait for an official fix till ANTLR 4 is out. Before that, please use the workaround found by rgl.

For more information, you can read http://antlr.1301665.n2.nabble.com/C-target-td7446146.html

shawnlian Dec 13, 2012 at 12:05 PM 
rgl:
You are right! building the 7.5 version that will occur "Unknown build error: Exception has been thrown by the target of an invocation." in project "SharpSnmpLib.AST".

The problem was made by "ANTLR". "ANTLR" detects which language on the machine, and try to load the mapping language file.if the file not exists then throw exception.

For my example: change the en.stg to zh.stg, it work well. All projects compiled successfully.

thanks you found it.

tdracz Nov 2, 2012 at 12:07 PM 
Thanks rgl! That saved my day (my system locale is non-English too).

rgl Mar 22, 2012 at 10:24 AM 
To be able to build this library on my machine I had to copy lib\ANTLR\Tool\Templates\messages\languages\en.stg to pt.stg (my machine default locale is Portuguese). I've figured this out by manually running the lib\ANTLR\Antlr3.exe command from the command prompt.