VS 2010 Default Class Template for Windows Phone 7 - visual-studio-2010

Hi I've created a new WP7 project. Then I add a new project of type Windows Phone Class Library and by default the project has System.Net, System.Windows and System.Xml references beside other references. I don't need them in my Class Library so I delete them but when I create a new class Visual Studio create the following class :
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace WP7
{
public class Class1
{
}
}
but I've already removed the references System.Net & System.Windows. I'm getting an error when I try to compile the solution.
How I can modify the default template ?
I want to be something like
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
namespace WP7
{
public class Class1
{
}
}
I think this is a bug in VS2010. It doesn't respect the the current references of the project when adding a new class. How can I report this bug to MS ?

this is just how item templates and project templates work. You could create your own set, but that just isn't going to be quick and easy.
The idea is that these assemblies are needed in the majority of apps.
Since they are present on the device and not packaged into your .XAP, there is no net effect to your app.

Related

Can we run custom script for code cleanup using Visualstudio or Resharper?

I want to save space while printing source code in visual studio. Is it possible to combine multiple using namespace statements at the beginning of *.cs file to single line using resharper in visualstudio, or using some script that can be run using Resharper code cleanup. I want
using System;
using System.Collections.Generic;
using System.Net;
to be formatted as
using System;using System.Collections.Generic;using System.Net;

Can't find Microsoft.Phone in references XNA WP7

I want to open web browser using XNA for WP7,
from This Post I think I must use WebBrowserTask to do that,
but I don't know how to add Microsoft.Phone
I tried to right click on references but I can't find references Microsoft.Phone
I tried just type it in my code, but It still doesn't work..
Anyone know why? am I in the right track?
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;
using Microsoft.Phone; // <-- Error here
I use VS 2010 Express for windows phone, WP SDK 7.1.1, and Windows 8 Pro
Ok, on my PC this lib is situated here:
C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0
\Profile\WindowsPhone71\Microsoft.Phone.dll
You can add it from Solution Explorer:
References -> Add reference -> Browse
and then paste the path into the File name textbox.

Can't see some classes of CRM 2011

I'm developing my first application for CRM 2011.
I've imported all .dll necessary for development.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Crm.Sdk.Messages;
but when I call some simple classes like "Annotation", "Letter" , "Email",
the visual studio doesn't detect these classes.
Has anybody knows why?
You need to use the tool CrmSvcUtil that comes with the SDK in order to generate your strongly typed classes.
Create Early Bound Entity Classes with the Code Generation Tool (CrmSvcUtil.exe)

How to run a unit Test in Visual Studio 2010 using Watin

I have created a class library prject, and created a class as described in the Video Tutorial at Watin
and using the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using WatiN.Core;
namespace ClassLibrary2
{
[TestFixture]
[RequiresSTA]
public class Class1
{
[Test]
public void SearchForWatiNOnGoogle()
{
using (var browser = new IE("http://www.google.com"))
{
browser.TextField(Find.ByName("q")).TypeText("WatiN");
browser.Button(Find.ByName("btnG")).Click();
Assert.IsTrue(browser.ContainsText("WatiN"));
}
}
}
}
now what is the next step, How to run the test? Do I add the class library to a project and run calls the test method from code? or do I create a Unit Test Project (how?) ?
Thanks
To execute your test you need to compile your code, then run the test through a test runner.
The first way I ever did this was using the NUnit GUI
Compile your code to a class library. The result being a .dll file; something like MyTests.dll
Open the NUnit GUI. Start -> Programs -> etc etc etc.
In the NUnit GUI, open the .dll file that contain your tests.
In the NUnit GUI, select the test(s) you wish to run and click the Run button.
There are plenty of other ways to run your tests, but I believe the NUnit GUI to be the most basic for NUnit tests. Other options include: In Visual Studio via ReSharper, Gallio, in VS via External Tools, and many others.

VS 2010: Disable Fileheader for new class files

I recently noticed that Visual Studio 2010 (Professional) inserts a FileHeader automatically in new class files. I don't know when this started but some time ago this wasn't enabled. Also, since then the using directives are added after the namespace.
This is the way the file looks like after generation:
// -----------------------------------------------------------------------
// <copyright file="Class1.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
namespace MyNamespace
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/// <summary>
/// TODO: Update summary.
/// </summary>
public class Class1
{
}
}
And thats the way it should look like (and how I want it):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyNamespace
{
public class Class1
{
}
}
I disabled all extensions and all plugins, but the problem stays. Hopefully anyone here can tell my how to restore the previoous behaviour.
Thanks in advance
Visual studio uses templates to generate new files. You can read about how to create your own templates here http://stevesmithblog.com/blog/how-to-fix-visual-studio-file-templates/. The default templates are commonly stored in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates and it is these you'll want to edit if you want to globally replace the format.
For me the file headers showed up after installing Resharper and Stylecop.
To get rid of them I disabled the header inclusions in Resharper (Code Cleanup section) and also made sure the file header rules are no longer enforced in StyleCop. Next I modified the file templates stimms mentioned earlier. And finally I had to run devenv.exe /installvstemplates from the command line for Visual Studio to register the changes.
I think that is a ReSharper thing, Check your ReSharper settings.
http://www.jetbrains.com/resharper/webhelp/Code_Cleanup__Usage_Scenarios__Configuring_and_Inserting_a_Default_File_Header.html
http://blogs.jetbrains.com/dotnet/2010/12/automating-file-header-information-with-resharper/

Resources