Setup a private Nuget server, host your own Nuget feed

Before I start talking about how to create a private Nuget server, I need to show you how do you create a Nuget package by yourself.

To create a Nuget package, you can either use Nuget.exe command line tool to do it, or use Nuget Package Explorer. Nuget Package Explorer provides the nice neat interface to allow you create a nuget package without any knowledge of command-lines syntax. To download them both, from

http://nuget.codeplex.com/releases/view/58939 (Nuget.exe)

http://nuget.codeplex.com/releases/view/59864 (Nuget Package Explorer)

After you have created your own packages, you can now setup the private Nuget feed.

1. Create a web application in Visual Studio. I am using MVC as my Nuget server application.

2. Install “NuGet.Server” package from “Package Manager Console”.

3. Configure the package folders and ApiKey

  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="apiKey" value="1234" />
    <add key="packagesPath" value="C:\MyLocalNugetFeed" />
  </appSettings>

4. Deploy your application to IIS. And you server is running.

To view the feed and download packages.

Right click “Reference” folder of your project, Click “Manage Nuget Packages”.

image

Then add “http://youdomain.com/nuget” as your feed address.

Adding new feed to package sources

You will be able to see your feeds in the list.

To publish a package

You can use Nuget Package Explorer or Nuget.exe.

Nuget.exe

image

Nuget Package Explorer, enter your publish Url and ApiKey then click Publish.

image

What are you waiting for to get your own Nuget feed and share code snippets or libraries with your mates!!

Here are some reference links may help you.

http://docs.nuget.org/docs/creating-packages/hosting-your-own-nuget-feeds

http://docs.nuget.org/docs/reference/command-line-reference

Modify or Override the default t4 templates in MVC

When you create a new View or Controller in a mvc project. It is T4 templates to generate the piece of code for a new view or controller.

image

image

The templates are located in

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3

or

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3

We can bring these templates to our local project by dragging the “CodeTemplate” folder to Visusal Studio from Windows File Explorer.

image

You will see some compilation errors, these will be fixed after you have clear all the templates’ property “CustomTool”. Just clear the string out.

You can add your own templates as well. Next time when you add a new view, or controller, you will see the project is using your local templates to create them.

This is very helpful and I have Learned this trick from Scott Hanselman.

Here is the blog entry from him, if you want to read more about it.

http://www.hanselman.com/blog/ModifyingTheDefaultCodeGenerationscaffoldingTemplatesInASPNETMVC.aspx

Windows Live Writer, the best plugin to insert source code

I have been having problems for publishing blogs from WLW (Windows Live Writer) when there are source codes embedded into the blog. It is always formatted poorly or messed up in html.

Here is the syntax we need to use for WordPress to format our source codes.

image

And it doesn’t look right if I post the blog using WLW (Windows Live Writer), and I figure out I need to modify the codes in the source view.

image

It is quite annoying that I have to do this every time. I have tried a bunch of plugins from WLW and none of them works right for me. Until I found this ONE! http://richhewlett.com/wlwsourcecodeplugin/

What you need to do is, copy the codes from Visual Studio and paste into the plugin box. And configure a few settings. It will make it right for you. Problem solved!!!! HOOYA.

It is version 1.3.0, please download from here

Version 1.3.0  (Recommended)
More Details
Download Now

Nuget commands to find packages and install them

I have been using Nuget in Visual Studio 2010, it is a time saver and make my life a lot easier.

To use Nuget, open visual studio 2010 => Tools => Library Package Manager => Package Manager Console.

So in the console, you can type your nuget shell commands to list available packages and install them to particular project.

To list packages,


PM> get-package –listavailable Elmah

You will get a list of available packages,

image

To install a package, (such as Elmah.MVC)

PM> install-package Elmah.MVC 

Nuget will install Elmah and its all dependencies. It also setup the settings in web.config

Isn’t that awesome!

For a full reference of Nuget shell commands, check out this link

http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference

 

MVC mini profiler, a simple effective profiler for mvc

Use Nuget to download mini profilder,

install-package miniprofiler

To use it, start the profiler in Global.asax, Application_BeginRequest()

protected void Application_BeginRequest()

{

    if (Request.IsLocal)

    {

        MiniProfiler.Start();

    }

}

Write a condition to start the profiler, for Local Request, for special users, etc.

To use profiler for your code,

var profiler = MiniProfiler.Current; // it's ok if this is null

using (profiler.Step("Set page title"))
{
    for(int i=0;i<100;i++){

//do something

}

}

To display on the page, you need to include the profiler to _Layout.cshtml,

    @MvcMiniProfiler.MiniProfiler.RenderIncludes()

To end a profiler, end it in Global.asax, Application_EndRequest(),

protected void Application_EndRequest()

{

    MiniProfiler.Stop();

}