in

ASPXWizard.net

.net and Ajax Community

Mina Labib

December 2009 - Posts

  • Adding double quote in NAnt task

    I was struggling this morning with issue in simple NAnt script, I was trying to uses <exec> task to call msbuild tool.

    Ok quick brief on the issue, NAnt 0.86 Beta 1 does not able to run its " href="http://nant.sourceforge.net/release/0.86-beta1/help/tasks/solution.html" target=_blank>" href="http://nant.sourceforge.net/release/0.86-beta1/help/tasks/solution.html" target=_blank><solution> task to build Microsoft Visual Studio solutions against Visual Studio 2008 solution files, however it can build solution for .NET 3.5 Framework. so I found two solutions –till now-, both of them are using MSBuild tool to build my solution with two different ways; first one is to use NAntContrib as extension for NAnt and use its " href="http://nantcontrib.sourceforge.net/release/0.85-rc4/help/tasks/msbuild.html" target=_blank>" href="http://nantcontrib.sourceforge.net/release/0.85-rc4/help/tasks/msbuild.html" target=_blank><msbuild> task to fire msbuild tool – I did not try that yet –, and the other one is to use NAnt " href="http://nant.sourceforge.net/release/latest/help/tasks/exec.html" target=_blank>" href="http://nant.sourceforge.net/release/latest/help/tasks/exec.html" target=_blank><exec> task to call msbuild tool and throw to it my solution file as parameter; and while I am try that I found issue, I need to add /p:Platform=”Any CPU” as msbuild command switch but how to add double quote to task attributes, it fails if I wrote:

    <exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe" commandline="mysolution.sln /p:Platform=”Any CPU”"/>

    Fortunately, I found nice simple post to solve this issue by adding property to NAnt script with double quote as value and use it in my command as following:

    <property name="dbl_quote" value='"'/>
    <exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe" commandline="mysolution.sln /p:Platform=”${dbl_quote}Any CPU${dbl_quote}"/>
    It is nice and quick solution.
    Posted Dec 18 2009, 04:49 AM by minalabib with no comments
    Filed under: ,
  • ASP.NET MVC 2 RC

    About month ago the Beta version was released, and now ASP.NET MVC team is announcing to day that ASP.NET MVC 2 RC is out there and that release candidate is ready to be downloaded and play around with.

    Mainly it is focused in bug fixing, improving current features, and performance tuning and you can as usual read the release notes for more details. Mainly the focus in Beta and RC releases are in the validation, validation localization, HTML.RenderAction and HTML.Action, you will find more details in this post.

    This version is for Visual Studio 2008 and should come in the RTM of Visual studio 2010 which should come out sometime in next March.

  • Steps to enable NAnt intellisense in Visual Studio

    NAnt is helpful, open source, and free tool for automated .NET-build process, same as Ant but it is targeting .NET frameworks rather than Java, and according to Wikipedia the name NAnt is coming from Not Ant :)

    NAnt allows you to build a script (XML Script) configuring tasks and dependencies with reach NAnt functions, expressions, data types etc…

    Alright, going back to this post purpose; here you are the steps to allow NAnt intellisense in VS 2008 (I believe for other VS versions too) in Windows operating systems.

    • Download Nant binaries or source code from here, I will go with latest one NAnt 0.86 Beta 1.
    • Extract the compressed folder and follow NAnt installation steps as explained here.
    • Copy nant.xsd file from extracted folder (<Base installation directory>\schema\nant.xsd)
    • Paste this file into XML schema folder in Visual Studio installation directory; it should be as following in x32 bit operating systems (C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas) or (C:\Program Files (x86)\Microsoft Visual Studio 9.0\Xml\Schemas) in x64 bit operating systems.
      You should be done now with those steps, do start new NAnt XML script and get use of Intellisense, create new XML file in VS 2008, and in the root node <project> add the attribute xmlns=” now you should see NAnt schema in the drop down list as bellow:
      NAnt01
      And now you have NAnt XML intellisense enabled in VS 2008 as bellow:
      NAnt02 
    Posted Dec 16 2009, 02:26 AM by minalabib with no comments
    Filed under: , ,
  • Extending Cache to Get Or Insert data

    In current project I was planning to build caching functionality to keep some shared and not frequently changed data, I figured out that I will be using a lot of Cache[string Key], Cache.Get(), and/or Cache.Insert() methods. and that means I have to check if the data is in the cache already and if not I have to insert the data to the cache object.

    I was thinking about having a method to check and update the cache without rewriting that over and over again, but that means I have to know what is the data type of the data needed to be stored, that brings us to Generics and Extensions to build extension methods to check the Cache object and get or insert data.

    I am using ASP.NET MVC 1.0 in this project, below is the extension method to get or insert into Cache object:

    using System;
    using System.Web.Caching;
    
    namespace CacheExtensions
    {
        public static class CasheExtension
        {
            public static T GetOrInsert<T>(this Cache Cache, string key, Func<T> generator)
            {
                var result = Cache[key];
                if (result != null)
                    return (T)result;
                result = (generator != null) ? generator() : default(T);
                Cache.Insert(key, result);
                return (T)result;
            }
        }
    }

    now you can consume it easily by calling the extended method as following:

    object o = HttpRuntime.Cache.GetOrInsert<object>("key1",GenObj);

    supposing GenObj is a pointer  to a method to generate an instance of type object.

    Actually I used the same technique to get or add data to the session object too.

    References: http://stackoverflow.com/questions/445050/how-can-i-cache-objects-in-asp-net-mvc

ASPXWizard.net some rights reserved 2005-2007
Powered by Community Server (Non-Commercial Edition), by Telligent Systems