When you develop with Entity Framework, you may need the SQL instruction passed to the SQL engine when your LINQ query is evaluated.
As you can see from the post ToTraceString Method in Entity Framework, both the System.Data.Objects.ObjectQuery and the System.Data.EntityClient.EntityCommand classed implement the ToTraceString() method, whose evaluation returs just the info you need.
An update in EF 6.1 allows to output the generated SQL doing:
context.Database.Log = Console.Write;
after having created the context, as explained in Logging and Intercepting Database Operations.
Sometimes, when working with corporate machines, it can happen that you have security issues that make your SharePoint development harder.
One of these problems is that even if you are machine administrator, or you have started Visual Studio as administrator, you still have problems with deploies, or you have DLL locked in the GAC and you are not able to update/delete them.
The solution to this problem is to remove the admin approval from the local policies:
- run the Local Security Policy MMC snap-in (from the start menu, run, type Local);
- go to Security Settings | Local Policies | Security Options
- disable "User Account Control: Run all administrators in Admin Approval"
- reboot the machine
I've seen this trick in the blog post Access Denied trying to uninstall assemblies from GAC.
How to develop to SharePoint without having SharePoint installed: you need to place the dll both in the hive folder and in the GAC.
This can be useful when it is needed to develop for both SharePoint 2007 and 2010: of course it's not possible to have both of them installed in a developer machine.
This hint has been taken from the blog post How to Perform SharePoint Development On A Client Workstation.
For a recent project I had to install WspBuilder Extensions in Visual Studio 2010 because of a SharePoint 2007 project.
I had some difficulty in remembering that for Visual Studio 2010 you need to install the WSPBuilder Extensions 2010 BETA 1.4.
Finally the best available walkthrough of WspBuilder is in the article WSPBuilder – Walkthrough of the Visual Studio Add-in.
After having described StyleCop in the blog post Using StyleCop to enforce source code standardization, here I describe FxCop.
FxCop is used to do code analysis of generated dlls.
It is automatically integrated in Visual Studio Ultimate edition. In the project properties, it will be possible to find a new "Code Analysis" tab. From this tab, it is possible to enable Code Analysis on build and eventually define a file for custom rules (like for StyleCop, it is a good idea to use a shared file used by all the projects in our solution).
You can find more details in the following articles:
StyleCop is a Visual Studio add-on used to enforce C# source code style rules.
After installation, you can run the checks from the new menu voice Tools | StyleCop; after execution, it will display its alterts as warnings in the Error window.
You can configure the type of warnings to be signaled with the online editor, that modifies the Settings.StyleCop file (simply double click on the file on your file system to edit it).
It's enough to have the Settings.StyleCop file (or better: a link, so that all projects reference a common file) in your Visual Studio project, so that after each build these additional checks are done. And StyleCop can work as a custom MSBuild task too.
You can find more informations in the blog post Enforcing coding standards with Microsoft StyleCop.
What to do when creating a new wsp in a Visual Studio 2010 SharePoint 2010 solution
- delete the created snk and add a reference to your global snk file (add existing item, Add As Link)
- from project properties, sign the assembly using the previously referenced strong name key file
- from project properties, choose the deployment configuration between Default and No Activation
- from project properties, disable the Auto-retract after deploying flag
- if not done during creation time, from the project properties set the site url
- add the needed references to the other assemblies in the solution
- unload the project file and add the tag needed to create the wsp file automatically, as described in my post Visual Studio 2010: how automatically build wsp packages after SharePoint 2010 build
- from package, advanced, add the assemblies you want to include in the wsp and deploy in GAC
- write one or more web-application scoped features, used to activate and deactivate the other features at site collection (SPSite) or site (SPWeb) scope
- if the wsp has not web-application scoped items, create an empy WebPart and a site collection scoped feature to be able to deploy the wsp to a single web-application, as described in my post SharePoint: how make your wsp deployable in a single web application
If you have ever developed SharePoint packages (wsp) with Visual Studio 2010, for sure you have feld a less than ideal user experience, because Visual Studio is not so integrated as WSPBuilder was with SharePoint 2007.
You can get a few of the better features of WSPBuilder installing the following add-on for Visual Studio: CKS: Development Tools Edition.
In particular, the commands I find more useful are:
- Copy to SharePoint Root
- Copy to GAC/BIN
- Recycle All SharePoint Application Pools
- Restart IIS
- Restart OWS Timer Process
- Attach to All SharePoint Processes
- Attach to IIS Worker Processes
- Attach to OWS Timer Process
In the post How To: Package on build in your Visual Studio SharePoint 2010 solution I've found to solution to build wsp packages automatically after SharePoint build:
- unload your csproj;
- before the closing tag,
- add the following lines:
Now you can reload your project and verify that after a build the wsp is recreated too.
Edit: in my experience the previous method is just fine and works ok, but, as seen in the post Visual Studio & SharePoint: how to create package as part of the build process, if you have problems with the previous tecnique, you can use insted:
If you need to save or change the Visual Studio client password, you can launch the Credential Manager (from Control Panel) and add/edit a row corresponding to your TFS url.