Radi Atanassov

SharePoint MCM, MVP, MCT and owner of OneBit Software

Recompiling your own version of the SharePoint code to suit your needs

Ever been pissed off at the SharePoint code? Banging your head against the wall, trying to figure out why something is not working for you, you're looking at it with a reflection tool and just want to see what would happen if you change a single line of code?

You don't have the SharePoint source code, but you still want to fiddle with it and compile your own build? You might have never thought that is possible, but here in this post I will show you how!

This is by far extremely awesome and some seriously fun shit, so enjoy!

(Disclaimer: don't do this, seriously. Just learn from it. I am sure that reverse engineering is written to be forbidden somewhere. And don't do this anywhere near a production server.)

STEP 1) Get the Reflexil plugin, either in Reflector or Telerik JustDecompile. It is called "Assembly Editor" and is available as a JustDecompile Plugin. Ever since Red Gate basterdised Reflector I prefer Telerik JustDecompile, it is free and built in Sofia, where I live and where OneBit Software is located.

Once you get all the components in there, load your tool and the assembly that you want to fiddle with.

In my example I modify Microsoft.SharePoint.ApplicationPages.Administration.dll, to make the CA UI show that I have a custom build, but you could easily do this with Microsoft.SharePoint.dll or any other assembly.

STEP 2) Browse through the assembly and find the code you want to modify. If you are tweaking a property, you need to specifically select the getter or setter. The UI will look like below, with many tabs in the Reflexil UI:

Right-click and either choose to edit the instruction, or "Replace all with code" for the fun stuff.

STEP 3) You will end up in an interface looking like the one below. On the left you will see generated code, on the right you will see instruction information. In my example, I replaced return default(string); with return "Radi's Custom SP Build!";

Make sure the Compiler version is the one relevant for the assembly, in my case v3.5, and hit Compile. You will get standard compiler errors if you have screwed something up. Otherwise if successful, the Instructions on the right will change as per your modification. That stuff is IL, you might already be familiar.

STEP 4) Go ahead and save your modified assembly. It will prompt you to save it with "Patched" in the filename:

STEP 5) After you save it, Reflexil/Telerik JustDecompiler will tell you some very important stuff about the Strong Name of the assembly. This step is key to get this to work and there's deep theory about assembly signing coming to play.

Assemblies are usually signed with a key so that they don't get tampered with in the way I'm doing it. Unless you have the key you can't modify it and resign it. This is something that Visual Studio does when it builds an assembly.

You can either remove the Strong Name, or register the assembly for verification skipping. This is something you could do with the sn.exe tool, or just through the interface below:

"Register it for verification sipping" requires that "sn.exe" is in the path variable so the tool can call it. It will basically execute:

sn -Vr yourAssembly.dll

I had to add "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\x64" to my Environment PATH variable and restart JustDecompiler. You might want to do this before you edit assemblies so you don't have to do it again. This is what you will see if sn.exe is not found:

 

STEP 6) What you should see next is the patched assembly, but the most important part is the PublicKeyToken, it should not be null:

 

STEP 7) The last step, rename the "Patched" DLL to its original name, then do an IISRESET.

 

And here she is, the most beautiful SharePoint release ever:

Please comment if you like this post!

“Activate on Default” confusion and features scoped at Web Application level

When creating SharePoint features in Visual Studio 2010, one of the settings that defaults to True is “Activate on Default”.

image

There is a lot of confusion as to what this setting actually does:

  • It ONLY applies to features scoped at Farm and Web Application levels. You can still modify it for other features, but it doesn’t do anything.
  • Any feature (Farm or WebApplication) with that setting set to True will automatically activate when you deploy the WSP solution, no matter which way you deploy it (Install-SPSolution, stsasm.exe, Central Administration)

This setting is not related to the deployment configuration settings in Visual Studio 2010:

clip_image001

These features will still activate, even if VS’s deployment configuration is set to “No Activation”.

Where can this be an inconvenience?

When you create features that deploy Timer Jobs at the Web Application level, you really want to have “Activate on Default” set to False. Otherwise, your feature will be activated on ALL web applications. I did some tests and found out that even if your WSP Solution is not global and is deployed to a specific Web Application, your feature will still get activated. Dangerous, you really want your Timer Jobs to be running where they are meant to run, i.e. don’t deploy Timer Jobs to Central Administration unless you really need to.

If you are ever trying to find out why your Timer Jobs are “attached” to all web applications, this might be why.

I’m a SharePoint Server MVP!!!

It was near the end of my working day, I was just about to do code reviews and catch-ups with my team, when I got the email:

“Congratulations! We are pleased to present you with the 2011 Microsoft® MVP Award!”

My excitement is warranted – it is my first time. I feel honoured and would like to thank everyone who contributed towards my nomination and my eventual award.

I am grateful for all the people who inspire, challenge, listen, support, influence and motivate me to do my work. To me this award is really about you.

Just like the Master award, and like every other achievement, its not an end, but a start to new goals and targets. Becoming a SharePoint MCM was a real achievement, but it was more a beginning to new paths – people expect you to know, do the right thing, always solve the problems, give the right advice. Being a Master means you always have to be up-to-date, always know what's new, always aim to provide the best possible architecture and solution to customers, write the best code even, you must know what buttons to push and what levers to pull, and if you don’t know you must know where to get the answers. To me, becoming an MVP is similar – there’s a community out there and MVP’s support it. They develop it and inspire individuals. I’ve been “crowned” an MVP - now it’s my job to make the great community greater.

 

Uploading WSP files programmatically to remote SharePoint farms

I was researching the possibility to upload a WSP file remotely, without logon access to any SP servers on a farm.

This is possible with the SPFarm.Open method, as long as you have access to the database. Firewalls should also allow access.

I have created a simple solution to demonstrate this: go to this page and click Download

The code to achieve this is fairly simple:

SPFarm.Open
  1. string connString = txtConnectionString.Text;
  2.  
  3. SPFarm remoteFarm = SPFarm.Open(connString);
  4.  
  5. remoteFarm.Solutions.Add(txtWSPPath.Text);

Hope this helps!

SharePoint Development Days – Jan 2010 – отзиви

Благодаря, на всички които успяха да дойдат! Събрахме се 18 човека в зала за 15 души (:

Специални благодарности на New Horizons, бяха супер и го направиха този ден възможен. Не само, че ни предоставиха зала, но и кафе, съпорт, организация, възможност за обратна връзка и много усмивки.

New Horizons

В началото на деня разказах за решението, което ще разглеждаме, как ще го деплойваме, и защо. На кратко разгледахме как SharePoint отразява бизнес обекти и как да създаваме такива. Декларативният CAML за някой беше нещо ново, но успях да покажа как самият SharePoint си създава свойте сайтове и списъци. Разгледахме и създаването на Site Templates, и как те пакетират нашите компоненти.

Благодарение на Мартин (от Абилитикс) обядът също беше успешен (:

Във втората част от деня погледнахме и web parts и тяхният life-cycle. Продължихме с Application Pages. Показах и малко C# код, но не стигнахме до създаване на custom controls и писане на CAML queries ):

Според мен деня мина добре, аз лично съм доволен и успях да се запозная с всички. Материала може би беше малко advanced за тези, които не са работили много с SharePoint. Visual Studio ми създаде проблеми, но те не пречиха на прогреса (евентуално причинителят беше WSPBuilder…).

Надявам се, всеки взе нещо със себеси, което може да го използва в бъдещите си проекти!

Презентацията можете да си я изтеглите от следния линк: NHBG_SharePoint_BG.ppt

Задачите, които приготвих: SharePointDevelopmentDaysJan2010.doc

Решението и кратко описание ще намерите на този линк: Code from SharePoint Development Days Jan 2010 

Сега започвам да правя планове по следващото събитие… надявам се отново да се видим!

Ради А.

Нов Блог!

Тази седмица присъствам на SharePoint 2010 Ignite Training в Берлин. Това е invite-only трейнинг с цел повишаване на общите познания по SP2010. Ще открия този блог със серия от постове, които покриват нещата които научавам всеки ден от този трейнинг. Тази информация е публична, така че ще споделям всичко което науча.

Записал съм се за Developer stream, като заедно с мене са Тишо (от Майкрософт) и колегата Росен. Росен се записа като IT PRO за да обхванем всики теми.

Днес е откриването и въвеждането в SP2010, и направо нямам търпение (: . След обяд навлизаме в същноста – Deployment with Features and Solutions.

Ще Ви разкажа какво се случи и какво трябва да знаем за Deployment с SharePoint 2010.