NuGet Package Manager or How to make “source code sharing” across projects much better

Introduction

In a company with more than one development project sometime it happens that someone says: Hey, we need a common logging component shared across all projects.
Now the solution could be to develop such a logging component and share the assembly with all projects. However, if there is some code that should/must be unique to each project it is a bit more complicated. If you want to do that with SharePoint 2010 and build a logging component on top of the ULS log and want each project to be configurable in the Central Administration you need to know all future projects and categories or you need some unique code.

Note: The logging component is only a very easy example and might not be the best one.

NuGet

Microsoft created NuGet. A package manager for Visual Studio. Quote of the official site:

NuGet is a Visual Studio extension that makes it easy to install and update open source libraries and tools in Visual Studio.

You can add it easily to Visual Studio 2010 by Tools->Extension Manager. Search for “NuGet”. After it is installed, you can add packages to a project by right clicking on a project in the Solution Explorer and click “Add Library Package Reference…”

image

Now as a company you don’t want your super-fancy code to show up for everyone as open-source. Therefore, NuGet can have more than one package source. You can even use a file share. Open Tools->Library Package Manager->Package Manager Settings:

image image

Bring it together

To get rid of “each project copy the source from the source of the other project from the source of the source of the source from another project” you can now use NuGet.

The idea is:
- Create the Logger.cs file
- Add TODOs to the code where the developer need to change something
- Make a NuGet package from it
- Let the project teams use the NuGet package (and distribute updates to the source automatically as well!)

Advantage: There is only one source! And if the owner of the NuGet package updates it, all project teams will be automatically notified about an update!

Create the NuGet package

In my example I talk about the comon logger component. A single Logger.cs file. However, NuGet can handle even more complex packages with PowerShell code, etc.

So download the NuGet command-line tool and create a new folder where all the stuff for the package will go to.

Open a command prompt and enter:

nuget spec

This will automatically create an empty package specification file called Package.nuspec. Open this file in notepad and modify the required values. Also rename the file to match the id property.

image

Now create a folder called “content”. Everything in this folder will be merged into the solution on installation of the package. So I put the file Logger.cs in this folder.
However, I don’t want that all users are required to use the same namespace, so you can change the file extension to “.cs.pp” to let NuGet “pre-process” the file.

Within the file you can then set some tokens to be replaced on installation. You can find a list of available properties here on MSDN.

The folder structure looks like this:

image

And the Logger.cs.pp in the content folder:

image

As you can see, I used the token $rootnamespace$. That one will be replaced by the root namespace of the target project.

Ok, lets make a package:

nuget pack

The output is a file called SPLogger.1.0.nupkg. You can publish it to the official NuGet package server or use it only internally by copying it to a file share.
Now open Visual Studio add the file share as a package source and search for it in the “Add Library Package Reference” window or open the NuGet console in Visual Studio (View->Other Windows->Package Manager Console) and type:

Install-Package SPLogger

image

That’s it. If you change the version number in your .nuspec file, create a new package and copy it also to your file share, the project team can decide to update to the latest version in the “Library Package Reference” dialog. You can even uninstall the package and everything will be removed from the project without leaving anything behind.

My first Windows Phone 7 application: MySite for WP7 - Part 1

A few weeks ago, my employer, Avanade Germany, announced an internal “Windows Phone 7 Contest”. The goal is to create a (business) app for Microsofts new Windows Phone 7 (WP7) system. I just had some ideas and decided to go with “MySite for WP7”. At least because I’m working in the “Portals & Collaboration” Service Line and I really like the new SharePoint 2010 MySite. That, and because the price for the best three apps is an Xbox 360 with Kinect. Winking smile

Overview

If you have no idea, what the SharePoint 2010 MySite is, here is a short introduction: Think about a “little” Facebook (social network) within your company. You can write status messages, see a newsfeed about your colleagues, post comments on the note boards of your colleagues, upload pictures, etc.

I know, that WP7 comes with SharePoint integration, but without a cool client for the MySite. I will try to build one (and hopefully win the Xbox).

Start with WP7

I will not give you an overview what you need to start, because there are a lot of resources to learn WP7 development. I already know .NET, C#, SharePoint and Silverlight and that’s everything you need to start. Download the Development Toolkit (for free) and start up Visual Studio.

First of all I decided to go with the Panorama Template, because it is easy to use and looks really nice. Also it supports my idea of different MySite tasks. The design-time support is great as well. If you click on the panorama page in the XAML code, the designer shows the corresponding page.

image

But before I go into much UI details, we should thought about the backend.

How to connect to SharePoint?

SharepPoint 2010 provides a web services API (WCF and legacy ASMX) to access most of the SharePoint functionality. Therefore I tried to access these services directly from the phone, but that did not work, because of two main points:

So obviously a workaround is required. Here is my idea of a “proxy service”:

image

That means, the WP7 app connects to an SSL secured WCF (silverlight-enabled) proxy service (without authentication) in the cloud. The service then connects to the SharePoint service with the provided credentials. For privacy reasons, a company that do not want to transmit sensitive data over the cloud service can host their own proxy service within their secure environment to make it accessible by their employees.

The proxy service can for example get the current status message from your MySite:

public string GetStatus(AccountCredentials credentials)
{
  var client = GetProfileServiceClient(credentials);

  string fqnUsername = credentials.Domain + "\\" + credentials.Username;
  var data = client.GetUserProfileByName(fqnUsername);

  var statusProp = (from d in data
                    where d.Name == "SPS-StatusNotes"
                    select d).FirstOrDefault();

  return statusProp.Values[0].Value.ToString();
}

I defined a class AccountCredentials which contains username, domain, password and SharePoint MySite URL. This data is entered in the WP7 app by the user. Now the proxy service is called with this data and calls the SharePoint profile service (with the URL provided) to get the current status message.

This approach is not only for communicating with SharePoint, but can also be used with other services which cannot directly be called from the phone.

Alternative to a Proxy Service: UAG

Another fairly new (at least for me) way is the Forefront Unified Access Gateway (UAG). See also this video from TechED. In the video you can see, that Microsoft requires a company to have a UAG in place to use the build-in SharePoint features of WP7. So it seems, that also Microsoft cannot use NTLM on WP7.

WP7 with UAG uses HTTPS for all communications and what is know as basic authentication. One problem why I’m currently not supporting UAG in my App is, because there are no developer resources how to integrate it in your own application. The only info you got from the video is to use signUrl.asp to get the token after authentication. If anyone has more info, please add a comment.

Learn more in part 2 of the series in a few days where I will talk about the User Interface.

Proxy Switcher meets Facebook, Twitter and SharePoint 2010 MySite

I was on vacation the last two weeks so I had some time for some funny things. For Proxy Switcher I thought it would be a nice idea to have an AddIn to set the status message of social networks on a network change. The two major players are Facebook and Twitter. Personally I’m not using Twitter, but that’s another story. Additionally, at Avanade we have our MySites on SharePoint 2010 with the new feature enabled to add status messages there as well. (See also our Avanade SharePoint Blog)

image

Your TODO now: Download Proxy Switcher (if its not already installed), then go to the More AddIns page to download the “Social Media Update Action AddIn”.

Browser Selector

UPDATE:

You can download the sources from https://github.com/mwiedemeyer/browserselector

 

Today I have created a little tool. I called it “Browser Selector”. It is for all people who uses more than one browser.

My scenario:

I’m using Opera and Internet Explorer. Opera for daily browsing and Internet Explorer for all Microsoft sites and for the company intranet.

Browser Selector now helps to avoid copy&paste url’s in one of the browsers depending on the url. Instead I can click directly on each url from all applications (Outlook, MSN Messenger, etc) or even enter the url in the start menu and it opens automatically in the correct browser!

Configuration:

To configure, which url will be opened in which browser, there is a config.xml file:

<?xml version="1.0" encoding="utf-8" ?>
<BrowserSelector>
  <Rules>
    <Rule Url="microsoft.com" Browser="IE" />
    <Rule Url="live.com" Browser="IE" />
  </Rules>
  <Browsers>
    <Browser Name="Opera" Path="C:\Program Files (x86)\Opera\opera.exe" Default="true" />
    <Browser Name="IE" Path="C:\Program Files (x86)\Internet Explorer\iexplore.exe" />
  </Browsers>
</BrowserSelector>

 

There you see a Rules section. In the Url attribute you can use regular expressions as well.
In the Browsers section you define all of your browsers and mark one as default which will be used if no rule matches.

Now download the msi, install it and configure it as you like. It is well tested with Windows 7 RC.

If you have any questions, problems or suggestions, write a comment.

K2 blackpearl: Command-line deployment hangs

I tried to deploy a K2 blackpearl process (developed and tested on server DEV in domain A) to a test environment (server TEST, domain B) via the command line, but it freezes at some stage.

Normally you could deploy a process from within Visual Studio with a click on “Deploy”. Then you will get a wizard to choose your environment. If your environments are not on the same domain, K2 blackpearl supports the deployment through the command line.

In Visual Studio right click on the process and select “Create Deploy Package”. After it finishes, you will find some files in the obj\Debug folder. One file is a .msbuild file.

I copied all files, as mentioned in the K2 docu, to the target machine and fired up:
msbuild MyProcess.msbuild /p:Environment=Test

First, it looks good, because my InfoPath form was deployed to the SharePoint site, then the console showed the following lines:

Deploy Processes: Task Started (26.02.2009 17:00:00)
Adding Process : MyProcess\Demo1

Nothing more! I waited about 30 minutes, but nothing happened, no error messages, nothing.

Long story short: The solution is, that the value of the “SharePoint Target Site” environment field MUST end with a “/” (e.g. “http://mossServer/targetSite/”)! You can change this within Visual Studio in the Environment Browser or directly in the .msbuild file.

No more comments…

Telerik RadEditor for SharePoint: Problem with custom tools

The RadEditor for MOSS 2007 version 4.5.3.0 has a Bug, which is very annoying...

You create a new custom tool in the ToolsFile.xml and set the “showtext” property.

<tool name="CustomToolName" showtext="true" /> 

Then you create a corresponding javascript method in the RadEditorCommandList.

RadEditorCommandList["CustomToolName"] = function(commandName, editr, oTool)
{
  (...)
}

If you now click on this new Tool Button, the RadEditor shows the message “Could not find the command xxx. Please update your command list.”

radeditor_error

The solution for that: Remove the “showtext” property from your tool in the ToolsFile.xml and everything is working as expected.

Error creating a new SharePoint Site through the Object Model

I have an issue creating a new Web Site programatically. Sometimes, the following exception occurs:

Content type '0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE811' not found in web 'xxx'

Live Search has no solution (by the way: Google has no solution as well ;-)). The only thing you can do is re-run the SharePoint Products and Configuration Wizard. After that, the error disappears and the site creation process is successful.

The weird thing is, that the content type ID is the ID from the “PageLayout” Content Type... If anyone found another solution I would be very interested.

Microsoft Windows SharePoint Services 3.0 – Application Development

Nachdem ich ja seit einiger Zeit MCPD EA bin, habe ich letzte Woche eine weitere Prüfung, die 70-541 abgelegt und bin nun also: MC Technology Specialist: Microsoft Windows SharePoint Services 3.0: Application Development

MCTS SharePoint Application Development

Mein Transcript wie gehabt hier zu finden: http://www.microsoft.com/learning/mcp/transcripts

ID: 761136
Kennwort: marcowiedemeyer

CMS mit SharePoint 2007 - Teil 1: Das SharePoint Variation System

Ich weiß, dass es einige Webseiten gibt, die insgesamt wahrscheinlich eine Menge Gründe nennen können, warum man Variations mit SharePoint 2007 nicht einsetzen sollte.

Im aktuellen Projekt war die Entscheidung für Variations bereits lange vor Beginn gefallen...

Daher ein paar nützliche Hinweise die man evtl. vorher beachten sollte oder die im Nachhinein vielleicht noch was retten können. ;-)

  1. Insgesamt ist das Variationsystem leider sehr instabil, auch mit installiertem SP1.
    Beispiel: Für die Migration von einem vorhandenen alten System haben wir u.a. ein Tool geschrieben, um aus Einträgen einer SharePoint Liste Sites und Pages auf einem Zielsystem zu erstellen. Sei es über as SP Objektmodell oder über stsadm, stellenweise und aus unerfindlichen Gründen knallt es beim Anlegen der Variations. Da die Sourcesprache aber (durch unseren code) (meistens) korrekt angelegt wird, ist der dahinterliegende Timerjob des Variationsystems das Problem.
    Eine wirkliche Lösung gibt es offensichtlich bisher nicht, daher führen wir das Erstellen der Sites und Pages nun verzögert aus, um jeweils nach ein paar Sites erstmal auf den SharePoint Timerjob zu warten...
  2. Variations per SharePoint Solution/Feature deployen bereitete uns ebenfalls einige Kopfschmerzen.
    Die Labels der Variationen die man anlegen möchte, lassen sich noch relativ leicht über ein paar Zeilen code in einem Feature Receiver anlegen. Um nun die Hierarchien zu erstellen, kann man entweder über die GUI gehen und auf den Button "Create Hierarchies" klicken oder man macht auch das per Code. Sinnvoll ist es, damit man später das ganze wirklich ohne manuelle Eingriffe von einem Administrator installieren lassen kann. Leider will Microsoft das wohl nicht, denn die zugehörige Klasse, bzw. Methode ist als internal deklariert und somit nicht verfügbar. Da das inakzeptabel ist, half nur ein Artikel von Codeplex, in dem beschrieben wird, wie man mittels Reflection doch noch zum gewünschten Ergebnis kommt. Und ja, die Alternative die Seite per WebRequest aus dem Code raus anzustoßen und vorher entsprechend zu manipulieren funktioniert nur bedingt und natürlich schon gar nicht zusammen mit Mehrsprachigkeit ;-)
  3. Custom ASP.NET 2.0 WebParts und Variations vertragen sich leider gar nicht!
    Beispiel: Eine Page erstellen, ein (selbst geschriebenes) WebPart hinzufügen und Publish klicken. Das Ergebnis ist ein leerer Eintrag im Variation Log, wo dann zwar Datum und Uhrzeit, aber weder Success, noch Failure Meldungen stehen.
    Weiterhin passiert dann einfach nichts mehr. Entfernt man das WebPart und klickt erneut auf Publish, funktioniert alles wieder wie es sollte.
    Nach einiger Recherche gibt es dazu offensichtlich 2 Lösungen:
    1. Man erbt von Microsoft.SharePoint.WebPartPages.WebPart anstatt von System.Web.UI.WebControls.WebParts.WebPart, was jedoch laut Microsoft nicht empfohlen ist, oder
    2. Installiert neben den Post-SP1 Hotfixes vom 31. Januar 2008 auch noch das 21. Februar 2008 Hotfix Package, was genau dieses Problem behebt. Somit können dann auch bereits vorhandene ASP.NET WebParts verwendet werden.

Weitere Teile folgen, denn noch ist das Projekt nicht zu Ende... Im nächsten Beitrag geht es dann um das ebenfalls allseits beliebte Content Deployment und warum  ich das ganze nahezu komplett neu Entwickelt habe...