.NET External Configuration & Build Process

clock October 24, 2008 19:57 by author Galcho |

It is very good practice to have several environments when creating a software solution - typical environments are Development -> Integration -> Staging -> Production environments. Also having Automated Continuous Integration server like CruiseControl.NET can greatly improve teamwork and quality of developed solution. Of course having a solution build (by CruiseControl.NET) you might want to have the installation project also build... and you will need a deployment procedure so the steps would look like these:

  1. Check-in source code changes
  2. Trigger a build on CI build server for the solution
  3. Trigger a build on CI build server for the build package
  4. Execute publish script which will deploy binaries to certain environment/servers and will change app settings, connection strings etc.

Example project setup can be seen on Omar Al Zabir's blog post ASP.NET website Continuous Integration+Deployment using CruiseControl.NET, Subversion, MSBuild and Robocopy.

 

Of course having all changes for different environments in publish script would make it big and difficult to maintain. This is why it is better to keep all environment/servers specific settings outside of the project. One option is machine.config. And storing it in source control, of course.

 

Another option is having all those settings in separate folder. I wasn’t aware of this option of .NET Configuration API and I was disappointed  when I found that XInclude is not supported. Fortunately there configSource section attribute which allows to achieve same functionality. For some ( more here ) this might be well known but I found this recently and AFAIK it is not widely used.

 

So you can specify web.config/app.config file like this:

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <configuration>
   3:   <connectionStrings configSource="ConnectionStrings.config" ></connectionStrings>
   4:   <appSettings configSource="settings.config"></appSettings>
   5: </configuration>

and then specify actual configuration in external files. Here are my examples for ConnectionStrings.config

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <connectionStrings>
   3:   <add name="cs1" connectionString="Data Source=myServerAddress;Failover Partner=myMirrorServer;Initial Catalog=myDataBase;Integrated Security=True;"/>
   4: </connectionStrings>

and Settings.config

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <appSettings>
   3:   <add key="s1" value="Some very important setting"/>
   4: </appSettings>

 

As you can see from example the only important thing is to have root element of external file named same as referenced section in the core config file.

and after that you can simply get the values as usual:

   1: class Program
   2: {
   3:     static void Main(string[] args)
   4:     {
   5:         Console.WriteLine("cs1: {0}", ConfigurationManager.ConnectionStrings["cs1"].ConnectionString);
   6:         Console.WriteLine("s1: {0}", ConfigurationManager.AppSettings["s1"]);
   7:         Console.ReadLine();
   8:     }
   9: }

 

This means you can refactor configuration of existing .NET applications without having to touch the code or even recompile. Just be careful :)

Happy XML/Config refactoring :) !



(Red Gate's) .NET Reflector

clock September 7, 2008 20:49 by author Galcho |

I've just read that the Red Gate's acquires the one of most widely used tools that .NET developers use - .NET Reflector.

Fortunately  there will be free version for the community.

Read full talk on simple-talk - The Future of Reflector.



Hug a developer... today

clock August 29, 2008 12:11 by author Galcho |

Thanks to Derek.

So this is the world of software development. Welcome in my world :P



Visual Studio 2008 SP1 is here

clock August 11, 2008 19:26 by author Galcho |

Well. The wait is over. Visual Studio 2008 SP1 is here.

Visual Studio 2008 SP1 delivers:

  • Improved WPF designers
  • SQL Server 2008 support
  • ADO.NET Entity Designer
  • Visual Basic and Visual C++ components and tools (including an MFC-based Office 2007 style ‘Ribbon’)
  • Visual Studio Team System Team Foundation Server (TFS) addresses customer feedback on version control usability and performance, email integration with work item tracking and full support for hosting on SQL Server 2008
  • Richer JavaScript support, enhanced AJAX and data tools, and Web site deployment improvements

The .NET Framework 3.5 SP1 delivers:

  • Performance increases between 20-45% for WPF-based applications – without having to change any code
  • WCF improvements that give developers more control over the way they access data and services
  • Streamlined installation experience for client applications
  • Improvements in the area of data platform, such as the ADO.NET Entity Framework, ADO.NET Data Services and support for SQL Server 2008’s new features

and more... Read more on what's included in VS 2008 SP1.

Download install .exe.
Download .iso version.



How Visual Studio &amp; C# are tested

clock July 23, 2008 15:50 by author Galcho |

Lately Microsoft put a lot effort in testing and this combined with the whole process & dogfooding create better products. Even better they do not hide it but are generous and share details with us. Recently a new test center was announced.

The Microsoft Tester Center showcases the test discipline as an integral part of the application lifecycle, describes test roles and responsibilities, and promotes the test investments required to deliver high-quality software.

 

Kirill Osenkov - SDET @ C# team shares some facts about his job:

    • We develop all of our test code using most recent builds of Visual Studio "10" and C# 4.0.
    • We do almost no manual testing - almost all of our tests are automated, which means they can run on a lab machine unattended.
    • We run our tests on a variety of operating systems, languages and VS SKUs (e.g. Visual C# Express 2008 on Japanese Vista or VSTS on Windows Server 2008 with Visual Studio 2005 already installed side-by-side).
    • The Visual Studio Managed Languages Team has about 30000 functional C# and VB tests which run overnight for about 12 hours on 5 to 10 lab machines (paralleled).
    • C# tests are written in C#, VB tests are written in VB, F# tests are written in F#.
    • We have a lot of automated UI tests - where mouse moves automatically and keyboard "types" on its own - its fun to sit and watch a test creating a C# project, opening files, typing, using refactorings, navigating, etc.
    • We prefer testing on the component level, bypassing the UI.
    • Our developers write unit-tests, while we concentrate on the functional testing and end-to-end scenarios.
    • We reach more than 70% code coverage with our tests - this is a required minimum for our team.
    • We use TFS (Team Foundation Server) for source control and work item tracking.
    • Many of our tests use a new data-driven test framework where our test scripts are written in XML and are interpreted by a script-like engine.
    • Most of Visual Studio tests are out-of-process - our tests attach to a Visual Studio process and control it using Remoting.
    • We have a "bug-bash" day about once a month where the entire team just uses Visual Studio and logs bugs.
    • We also have AppWeeks, where we form groups and build applications using our product.


ASP.NET Configuration @ Microsoft.com

clock July 15, 2008 17:35 by author Galcho |

I came across an article which covers some details of how ASP.NET web sites hosted by Microsoft are configured:

Key things are:

  1. Set the Compilation Switch Appropriately
  2. Use Medium Trust in ASP.NET 2.0
  3. Restrict Download of Specified File Types
  4. Be Careful When Adding Assembly References
  5. Remove Manually Set MaxConnection Values
  6. Beware of Unhandled Exceptions
  7. Ensure Proper Proxy Server Configuration
  8. Do Not Display Custom Errors to Everyone
  9. Know When to Enable Tracing
  10. Disable Session State Web Farms

Read full article for detailed explanations.



LINQ to SQL, Web.config and Connection Strings

clock July 9, 2008 20:50 by author Galcho |

I had some interesting adventures and in one of them I had to figure out the connection string key for LINQ to SQL DataContext class. I found this interesting blog post by Rick Strahl.

In short he describes that LINQ to SQL designer uses different approaches for web site project and class library one. Here is like the website project designer file is:

public DataClassesDataContext() :
        base(global::System.Configuration.ConfigurationManager.ConnectionStrings["TimeTrackerConnectionString"].ConnectionString, mappingSource)
{
    OnCreated();
}

while the class library one is:

public TimeTrakkerContext() :
 base(global::TimeTracker.Properties.Settings.Default.TimeTrackerConnectionString, mappingSource)
{
    OnCreated();
}

and you should overwrite it by adding connection string in web.config with name TimeTracker.Properties.Settings.TimeTrackerConnectionString like this

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
        <add name="TimeTracker.Properties.Settings.TimeTrackerConnectionString"
            connectionString="Data Source=.;Initial Catalog=TimeTracker;Integrated Security=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

Hmm it works with me too but I remember I had one record in my web.config like this TimeTracker.Properties.Settings.Default.TimeTrackerConnectionString and it worked till I made some change. Go find...



VS2008 seminars in New Horizons Bulgaria

clock June 19, 2008 14:38 by author Galcho |

Yesterday was last seminar from VS2008 series held in the New Horizons Bulgaria office with Microsoft Bulgaria support.

The seminars was very interesting (not only from my perspective of trainer) but also from audience perspective we see in their feedback. During high demand I am publishing presentations and demo scripts where available. It is always good to write code in live (although not very easy - try it ;) ) and this is why I cannot provide working demos - I have only my own cheat lists which I use in cse I am stuck somewhere.

Deep Dive in LINQ - Here I talked about new features in C# in details and how they are build internally(also described in my Introduction in LINQ and C# 3.0 (In Bulgarian) ). Also I covered LINQ to SQL, LINQ to XML.  In demos we took a look at C# syntax sugar, new ways to work with XML as well as some problems stated in Project Euler and solved with C# 3.0. Slides + Demo scripts (PPTX+DOCX - 1.22MB)

Develop Dynamic Web Sites with ASP.NET 3.5 - This session was focused on web development. Here I show new controls to work with LINQ to SQL data source declaratively. We took a look at ASP.NET Extensions (aka Futures): ASP.NET MVC, ASP.NET Dynamic Data, ASP.NET AJAX Integration, ADO.NET Data Services. All features was shown in code except ADO.NET Data Services. For ASP.NET AJAX was shown how to control Browser's Back Button from both server-side and client-side. Slides+Demo Scripts (PPTX+DOCX - 3.23 MB).

Overview of WCF, WF, WPF - Although these technologies are not new there is still some improvements in .NET 3.5. These components are very useful but their adoption is not very fast. We talked about the architectural decisions and challenges behind them. The demos show how to work with WCF in VS2008, How to create REST Service and how to expose JSON as result. WF demos show how to create simple sequential workflow. WPF demo presented project structure, generated code, XAML (of course) and WPF data binding basics. Slides+Demo Scripts (PPTX+DOCS - 10.8 MB).

Hope you'll find it useful.
As always any comments and feedback are very welcome.



Visual Studio 2008 and .NET Framework 3.5 Service Pack 1 Beta

clock May 13, 2008 13:00 by author Galcho |

There is no doubt that VS 2008 and .NET 3.5  totally rocks! ScottGu's division keeps pushing these products and constantly improving developer's productivity and shortening development cycle.

This time MS is preparing to release .NET 3.5 SP1 and VS 2008 SP1 releases.

In short here are improvements:

Improvements for Client Development
  • ASP.NET Data Scaffolding Support (ASP.NET Dynamic Data)
  • SP.NET Routing Engine (System.Web.Routing)
  • ASP.NET AJAX Back/Forward Button History Support
  • ASP.NET AJAX Script Combining Support - Omar Al Zabir wrote an extensive article about this approach.
  • Visual Studio 2008 Performance Improvements HTML Designer and HTML Source Editor
  • Visual Studio 2008 JavaScript Script Formatting and Code Preferences
  • Better Visual Studio Javascript Intellisense for Multiple Javascript/AJAX Frameworks - who can blame MS that force us to use their JS framework now?!
  • Visual Studio Refactoring Support for WCF Services in ASP.NET Projects
  • Visual Studio Support for Classic ASP Intellisense and Debugging - I am wondering when this technology will be declared dead :) (This is what I used in my first web apps too :))
Improvements for Client Development
  • Application Startup and Working Set Performance Improvements
  • New .NET Framework Client Profile Setup Package
  • New .NET Framework Setup Bootstrapper for Client Applications
  • ClickOnce Client Application Deployment Improvements
  • Windows Forms Controls
  • WPF Performance Improvements
  • WPF Data Improvements
  • WPF Extensible Shader Effects
  • WPF Interoperability with Direct3D
VS 2008 for WPF Improvements
  • Several performance improvements
  • Events tab support within the property browser
  • Ability to sort properties alphabetically in the property browser
  • Margin snaplines which makes form layout much quicker
  • Better designer support for TabControl, Expander, and Grid
  • Code initiated refactoring now updates your XAML (including both control declarations and event declarations in XAML)
  • Go to Definition and Find All References now support things declared in XAML
Data Development Improvements
  • SQL 2008 Support
  • ADO.NET Entity Framework and LINQ to Entities
  • ADO.NET Data Services
WCF Development Improvements
  • Significant scalability improvements (5-10x) in Web-hosted application scenarios
  • Support for using ADO.NET Entity Framework entities in WCF contracts
  • API usability improvements with DataContract Serializers, and with the UriTemplate and WCF web programming models
  • Enhanced TestClient support within VS 2008 SP1
  • New Hosting Wizard in VS 2008 SP1 for WCF Service Projects
  • Improved debugging support in partial trust scenarios
VB and C# Improvements !!!
Team Foundation Server Improvements

Pretty impressive...

Read full novel by Scott Guthrie here :)



My Sessions at Microsoft Days 2008 in Sofia, Bulgaria

clock April 30, 2008 15:37 by author Galcho |

MS Days 2008 in Bulgaria is in history now and I could say I had a nice two days. There were many lecturers (about 50) and 72 sessions in 6 tracks.

For those who missed my talks or are interested in slides here are summary of the sessions:

LINQ to XML - Data Access Technologies

This session was focused on the new API from XML team for .NET languages. I gave a side by side comparison between traditional DOM vs. LINQ to XML regarding those most common actions:

  • Create XML
  • Traverse XML
  • Transform XML

I covered also VB9 Literals. At the moment I started talking about VB I was thinking people would throw rocks at me (and some really considered that option:) ). But at the moment when repeated some of demos with VB9 code the audience was very impressed and they forgot about those rocks in their pockets. Even there were initial brainstorming whether same things can be implemented in C# with custom code.(Unfortunately this is a compiler feature and we cannot do it very easily).

Another thing I mentioned was LINQ to XSD.

I've decided that people will understand my points better if I write code in front of them instead of just explaining it. This is also more challenging :). I think it went well...

Here are the downloads:

IIS7 for IT Pros

IIS7 is the most interesting feature in Windows Server 2008 and I already had some talks about it. In this talk I covered (from administration perspective) following key topics:

  • What is missing in IIS 6.0
  • IIS7 module architecture and it's benefits
  • New .NET-like configuration files and metadata
  • Delegated Administration
  • Shared Configuration
  • Tracing and Diagnostics

The things I've demonstrated are:

  1. New tools - new management console as well as APPCMD command-line tool
  2. Richness of new error pages and generated trace file - it is whole HTML+JS application built with XML & XSLT with incredible amount of information.
  3. WCAT stress test with view of live requests on the server.
  4. Analyze server and site load using IIS7 Admin Pack features.

And here is the presentation: MS PowerPoint 2007 format (0.98 MB)

Any feedback is very welcome.