views:

32

answers:

2

Instead of writing

<@ Import Namespace="Microsoft.SharePoint" %>

on every view I create I know I can easily just edit my web.config file and add this:

...
<pages>
    <namespaces>
        <add namespace="Microsoft.SharePoint" />
    </namespaces>
</pages>

But this doesn't seem to work in design time. Visual Studio 2010 is not able to see SPContext unless I add these two lines on top of my view as well:

<%@ Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>

So how do I add assemblies globally as well as import namespaces so VS will be able to resolve classes/objects?

+1  A: 

It should work if you add the assembly in the Web.config, too.

Andrew Barber
Thanks Andrew. Kev's answer was more complete so I accepted his and upvoted yours as well, since you did provide correct info.
Robert Koritnik
+1 indeed it was; thanks for the vote! :)
Andrew Barber
+3  A: 

You also need to add the assembly to the <assemblies> section of the <compilation> section under <system.web>:

<compilation debug="false" targetFramework="4.0">
  <assemblies>
    <add 
      assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
  </assemblies>
</compilation>

Your targetFramework and debug attribute values may vary according to the framework version you're targetting and whether you're debugging or not.

Kev
Thought so myself and added it (well it was already added anyway). I only had to add namespace in `<pages>` element, but VS doesn't recognize `SPContext`.
Robert Koritnik
Thanks anyway. It does work as expected. the problem was, that global web.config was not part of my Asp.net MVC so I had to redefine <compilation><add assemby> andd it started working in Visual Studio as well. Stupid of me. Thanks anyway. I have to wait a few more minutes to accept your answer.
Robert Koritnik
@Robert - excellent.
Kev