Archive for the ‘C#’ Category
Troubles with Visual Studio on Windows 7 64Bit
I have had NO end of problems with developing on Windows 7 64 Bit….It seems Microsoft never created a 64 bit version, which means it buggers about with the OS like a 5 year old girl dressed in her Mums clothes….but every now and again that little girl trips in her high heels.
I managed to find something that so far, has been helping:
C:\Windows\Microsoft.NET\Framework64\v2.XXXX\LDR64.exe setwow
It does some jiggery-pokery under the hood and will enforce the CLR to run in 32 bit mode..which is fine by me – especially when running as normal on 64 bit adds nothing to me but headaches….
(Make sure you run the command prompt as Administrator else you’ll get problems trying to execute)
TeamCity Personal Builds
I use TeamCity as the continuous integration to our projects. It requires less setup and has nice GUIs for you to play with.
QAs with any new application, I installed all the plug ins, one of which is for Visual Studio.
I didn’t really pay much attention to it, I was just happy to have three new icons in my toolbar and soft satisfaction that TeamCity was a click away from Visual Studio.
I read a post today that informed me of the “Personal Builds”. This is the idea that – if I’m reading it right – you can test your changes against the server BEFORE committing. Obviously, there are conditions you can set to auto commit on success, but the main idea is to test your local changes do not break the build.
You can probably tell from the tone of my post that I am not all that convinced. The reason is because all I get is this:
Everytime I try to set the SVN path, I am presented with the message:
“Unable to use selected svn.exe" from xxxxxxx”
I am hoping this is because we are running two builds behind on TeamCity. I’ll update it on Monday and see if anything changes.
I’m not completely sold on the idea unless it can highlight this scenario:
Developer uses references to assemblies that are not included on the server or in the project, but only on his local machine. If you were to upload the changes, the build would break. But would this “Personal Build” notice this? If not, then what is the point?
I’ll see on Monday….
Post Build Event
Another one I always forget, putting in post build events in Visual Studio to handle developer customised configurations:
For Example:
The whole development team uses the same solution to work from. This solution is stored in SVN or similar. But each one of us uses a different connection string to connect to our local databases. How can we safeguard against a configuration file melee?
In the post build event of the project properties, enter a customised version of this line:
if %COMPUTERNAME% EQU KAMS-MACHINE copy $(ProjectDir)web.kam.config $(ProjectDir)web.config
Sandcastle – MSDN Style Documenting Tool
Another lazy post for reminding me the name of this tool. I always get it mixed up with “Castle” and “Windsor” and Google just returns me links on IoC…
"GetType" or "typeof"
Apparently, "GetType" is 7 times slower than "typeof".
I think you can do the calculations from here…
Hat Tip: Peter’s Software House
Descriptions for Enums
public enum OrderType { [Description("Per Unit")] PerUnit, [Description("Per 100")] Per100, [Description("Per Person")] PerPerson, [Description("Flat Rate")] FlatRate }
public static string EnumDescription<T> (T value) { DescriptionAttribute[] da = (DescriptionAttribute[])(typeof(T).GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false)); return da.Length > 0 ? da[0].Description : value.ToString(); }
foreach (OrderType item in Enum.GetValues(typeof(OrderType))) { base.Items.Add(new ListItem(Utility.EnumDescription(item), ((int) item).ToString())); }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
Put all three of the code snippets above together and you get MAGIC!!!
Courtesy of: Moggoly
Basic Event Handling in C#
public Transport Car
{
get { return _car; }
set
{
_car = value;
CarAdded(_distributor, EventArgs.Empty);
}
}
public event EventHandler CarAdded = delegate { };
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
Visual Studio 2008 .NET 3.5 Training Kit
Just download from Microsoft
Pex
Originally only available internally at Microsoft – Pex (Program eXploration) is an intelligent assistant to the programmer. From a parameterised unit test, it automatically produces a traditional unit test suite with high code coverage. In addition, it suggests to the programmer how to fix the bugs.
Web Configuration Editor
A surprisingly good and free web configuration editor. ASPhere