人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

March 6, 2007

宏: Visual Studio 2005 IDE 技巧和窍门

Filed under: Visual Studio

Visual Studio 2005 IDE 技巧和窍门

http://www.microsoft.com/china/msdn/library/langtool/vs2005/bb245788.mspx?mfr=true
1. 使用宏列举出所有的快捷键,导入配置文件

2.编辑快捷键的配置文件
My Documents\Visual Studio 2005\Settings\MyKeyboardShortcuts.vssettings

3.使用宏快速切换窗口布局,并将宏添加到ToolBar上.

4.Using team setting.file

5.Reset vs 的配置
devenv.exe /resetuserdata

November 10, 2006

Key not valid for use in specified state

When I create a data base in the VS2005, I get a error message box which
says: “An error occurred while processing the local data file:
Key not valid for use in specified state.” The .mdf was created successfully
but I can’t open it in VS2005.

Google tell me to delete the folder:
C:\Documents and Settings\<My Name>\Application Data\Microsoft\VisualStudio\8.0
I clean the folder, then I can use the data base as usual.

November 6, 2006

What’s Event Toaster?

Filed under: Visual Studio

装完了VS 2005 SDK后,在任务栏上出现了一个名为Event Toaster的图标,google后得知这是VS SDK Power Toys的一个小工具,可在VS工作时触发事件,执行一些命令,可在
VS 2005的Tools -> Option中PowerToys->EventToaster中进行设置.

参考:
http://blogs.msdn.com/aaronmar/archive/2006/07/19/671687.aspx

September 19, 2006

vs2005快捷键收集

Filed under: Visual Studio

//——-Coding
Ctrl+K, Ctrl+M
Surroun Ctrl+K, Ctrl+S
Code snippet Ctrl+K, Ctrl+X

注释 Ctrl+K, Ctrl+C
remove注释 Ctrl+K, Ctrl+U
Clipboard内容循环 Ctrl+Shift+V

删除当前行 Ctrl+Shift+L

自动换行 Ctrl+E, Ctrol+W

大小写 Ctrl+Shift+U, Ctrl+U

Navigation backward Ctrl+-
Navigation forward Ctrl+Shift+-
//——-Refactor
Rename Ctrl+R, Ctrl+R

//——-Search
渐进式搜索 Ctrl+I
反向渐进式搜索 Ctrl+Shift+I

//——-各种窗口
Command window Ctrl+Alt+A
Show breakpoints window Ctrl+Alt+B
Solution explore Ctrl+Alt+L
Code Definition window Ctrl+\, Ctrl+D

Exceptions Ctrl+Alt+E
Attach to Process Ctrl+Alt+P
Task List Ctrl+\,Ctrl+T
Error List Ctrl+\,Ctrl+E
Toolbox Ctrl+Alt+T
Class Ctrl+Shift+C

Macro Explore Alt+F8

//——-Bookmark
Bookmark window Ctrl+K, Ctrl+W
Toogle Bookmark Ctrl+K, Ctrl+K
Next Bookmark Ctrl+K, Ctrl+N
Previous Bookmark Ctrl+K, Ctrl+P
Clear Bookmarks Ctrl+K, Ctrl+L
Add Task List Ctrl+K, Ctrl+H
Remove Task List Ctrl+K, Ctrl+H

//——-Format
Format Ctrl+K, Ctrl+D

//——-Breakpoint
New breakpoint Ctrl+D
Clear all breakpoints Ctrl+Shift+F9

//——-VS
全屏 Shift+Alt+Enter
切换active file Ctrl+Tab
Open file Ctrl+O
New file Ctrl+N
New project Ctrl+Shift+N

August 11, 2006

VS2005 Debug 信息的输出

Filed under: Visual Studio

实验:
Console.Write(”>>Console:”);
System.Diagnostics.Debug.Write(”>>Debug:”);
System.Diagnostics.Trace.Write(”>>Trace:”);

————————————————————————-

在webpage和web service中,只有Debug.Write产生输出

另外:
Options->debugging->General
Redirect all output window text to the Immediate window (new one in VS 2005 )
Redirect all console output to the Quick Console window (一度出现,现在不见 )

June 14, 2006

注册表中VS安装文件的位置

Filed under: Visual Studio

有这样的case:
VS.net安装盘放在公司的一个共享目录里,在安装VS.net时选择了部分安装,
在用到未安装的组件时,VS.Net会安装这些组件,但VS.net安装路径被移动了,
此时,请修改注册表:
HLM\Software\Classes\Installer\Products\{GUID}\SourceList

{GUID}需要自己找.
9040F50EA9E01A84CA403EE5033306A4 为 vs.net 2003
845140B1CB334714B879DA9C7B494888 为 vs.net 2005 Team edition

June 10, 2006

听Alen讲MS Build

Filed under: Visual Studio

1. MS Build的位置
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

2. 相关namespace
Microsoft.Build.Framework
Microsoft.Build.Engine
Microsoft.Build.Utilities

3. MS build的 4个要素:
Target : task的组合
<Target Name=”Build”>
<Task1 Property1=”XX” Property2=”XXX”>
<Output TaskParameter=”NewVersion” PropertyName=”ET4NewVersion” />
</Task1>

<Testn> </Testn>

</Target>

Task : 可复用的执行单元, 由脚本和dll协同工作

<UsingTask TaskName=”VssGet” AssemblyFile=”$(DLL)” />

<Target Name=”Build”>
<VssVersion VssIni=”$(VssIni)” Property2 =”XXXX”>
<Output TaskParameter=”NewVersion” PropertyName=”ET4NewVersion” />
</VssVersion>
</Target>

public class VssGet : Microsoft.Build.Utilities.Task
{
//
// Properties….
//
[Required] //从脚本中读取
public string ProjectPath
{
get
{
return _projectPath;
}
set
{
_projectPath = value;
}
}

[Output]
public string Date
{
get
{
return DateTime.Today.ToShortDateString();
}
}
public override bool Execute()
{
}
}
Property: key-value 对,用来对build进行配置
<PropertyGroup>
<BuildDir>Build</BuildDir>
<DLL>..\GrapeCity.DailyBuild.dll</DLL>
</PropertyGroup>

使用property
<UsingTask TaskName=”XCopy” AssemblyFile=”$(DLL)” />
<XCopy Projects=”@(PublishOutputPath)” Destination=”$(TargetFolder)\LastBuild\Publish”/>

Item : Task的参数

4. 在命令行传入参数
MSBuild.exe MyProj.proj /property:Configuration=Debug

5. 执行外部命令
<PropertyGroup>
<EncryptPath>”D:\Work\DailyBuild\”</EncryptPath>
</PropertyGroup>

<Target Name=”Encrypt”>
<Exec IgnoreExitCode=”True”
Command=”$(EncryptPath)\Encrypt.bat”/>
</Target>

June 7, 2006

VS2005 AddIn Line Counter

Filed under: Visual Studio

Line Counter - Writing a Visual Studio 2005 Add-In

http://www.codeproject.com/useritems/LineCounterAddin.asp

除了提供了一个很不错的插件,这篇文章还教学了

1.AddIn的原理和写法

2.AddIn的安装

其中对资源的处理使用了Build event,是个不错的解决方案

AddIn的安装需要注意.AddIn 文件的部署,文章曰:

This is important for when VS tries to register the add-in. If it is missing, then the add-in will not register. This particular file is somewhat unique in that it is a shortcut. The actual location of this file should be in your {MyDocuments}\Visual Studio 2005\Addins\ folder. It should contain the following xml (NOTE: The [ProjectOutputPath] should match the output path of the project on your own system, so you will probably have to edit it).

If you need to add this file to the project, place it in the proper location under your My Documents folder first. When you add the file to the LineCounterAddin project, instead of clicking the Add button, use the down arrow next to it, and choose “Add As Link“.

有关.AddIn File可以参考

Packaging Add-ins and Toolbox Controls for use with Visual Studio Content Installer

http://blogs.msdn.com/chetanc/archive/2005/10/10/479000.aspx

VS2005 AddIn CoolCommands 3.0

Filed under: Visual Studio

CoolCommands 3.0 for Visual Studio 2005

http://weblogs.asp.net/gmilano/archive/2006/05/10/446010.aspx

装完后在Project的右键菜单上会多出很多功能,

Collapse All Project

Open Container Folder

VS Prompt Here

Resove Project Refrence

Refrence Manager

非常有用!

June 6, 2006

VS 中使用SOS

出自

More on debugging with SOS.DLL - enter Visual Studio
http://mtaulty.com/blog/archive/2004/08/06/628.aspx

FIX: Unmanaged debugging not possible until you install Visual C++ .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;813134

//—-调试Managed application
1. 设置project的属性,把”Enable Unmanaged Debugging”设置为true
否则在load sos时vs会报错:

SOS not available while Managed only debugging.
To load SOS, enable unmanaged debugging in your project properties.

如果没有安装 vc++.net, 上面的设置并不会有效果,使用F5直接运行project, vs会报错
—————————
Microsoft Development Environment
—————————
Error while trying to run project: Unable to start debugging.

Unable to start program ‘D:\Work2006\CursorTest\bin\Debug\CursorTest.exe’.

Unmanaged debugging is not available.

尝试使用 ctrl+F5启动程序,并Attach 进程,SOS也不能加载,提示:

SOS not available while Managed only debugging.
To load SOS, enable unmanaged debugging in your project properties.

3. 在 Immediate window (Debug-> Windows -> Immediate)中输入 .load sos
在Immediate window中输入 immed 和 cmd 可在Immediate mode和Command mode之间切换

//—-调试 dump file
1. File 打开 dump file

2. Debug->Start 等待中断

3. 在Immediate window中输入 .load sos

常用命令
!EEVersion
!ProcInfo
!ClrStack
!Help <command>
!

May 31, 2006

Synchronize Docuent Outline

Filed under: Visual Studio

在使用vs2005编辑网页时,选中一个tag,再使用右键菜单上的”Synchronize Docuent Outline”可以在Document OutLine中构造一个html tag树.

ctrl+shift+v

Filed under: Visual Studio

如果clipboard上存在多份数据,ctrl+shift+v可以循环paste这些内容.

May 25, 2006

MS Build 笔记

Filed under: Visual Studio

//—–MSBuild的执行路径
 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
 或在Visual Studio 2005 command prompt下直接运行
 

//——条件的使用 
<Configuration Condition=" ‘$(Configuration)’ == ‘’ ">
 Debug
</Configuration>

 <MakeDir Directories="$(CopyLocation)" Condition="!Exists(’$(CopyLocation)’)"/>

//——显示信息
<Target Name="Hello">
    <Message Text="Hello MSBuild" Importance="high"/>   
</Target>

//——什么是metadata
一个Item的属性,分为Well-known 和custom
所有的Item都可以使用Well-known的metadata
比如,以下的MyItem 包含了文件file C:\MyProject\Source\Program.cs
<ItemGroup>
    <MyItem Include="Source\Program.cs" />
</ItemGroup>
可以使用Well-known metadata %(FullPath)得到

Custon metadata应用范围在当前的project文件中.

使用metadata和使用well-known的语法相同:
%(RelativeDir)

//——MSBuild 特殊字符
使用 %xx 语法对特殊字符进行转义,xx为该字符的ASC码.

//——在 MSBuild Project中使用环境变量
引用环境变量的方法与引用项目文件中声明的变量的方法相同
 <FinalOutput>$(BIN_PATH)\MyAssembly.dll</FinalOutput>

//——什么是Transformation
Transformation的语法:
 @(ItemName->’TransformationDetails’)

ItemName is the name of the item you are transforming, and the TransformationDetails
can contain raw text, evaluated properties, and metadata references.
比如

 <Copy SourceFiles="@(Compile->’%(FullPath)’)"
        DestinationFiles="@(Compile->’$(MSBuildProjectDirectory)\$(CopyLocation)\%(RelativeDir)\%(FileName)%(Extension)’)"/>
       
 @(Compile->’%(FullPath)’) 会得到Item Compile的FullPath

//——-清除project 的bin目录
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CleanAllProjects">
    <!– Find all projects in or below the current directory –>
    <ItemGroup>
        <Projects Include="**\*.*proj" />
    </ItemGroup>
    <Target Name="CleanAllProjects">
        <MSBuild Projects="@(Projects)" Targets="Clean" StopOnFirstFailure="false" ContinueOnError="true">
        </MSBuild>
    </Target>
</Project>

//——-MSBuild 的Include 文件
这些文件存在于C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\

修改 Microsoft.Common.targets 中的CoreBuildDependsOn

Microsoft.Common.Tasks

//——-使用custom tasks扩展MS build:
1.从Microsoft.Build.Utilities.Task 派生
 public class TempFile : Task
 {
 
   public override bool Execute()
   {
      this.tempFilePath = System.IO.Path.GetTempFileName();
      return true;
   }
 }
 
2.写一个 project 文件
<UsingTask AssemblyFile="$(SharedTasksDir)\Tasks.dll" TaskName="Move"/>

//——-使用custom logger扩展MS build:

[尚待学习…]
 
 
 
 
参考
Compile Apps Your Way With Custom Tasks For The Microsoft Build Engine
http://msdn.microsoft.com/msdnmag/issues/06/06/InsideMSBuild/default.aspx

May 21, 2006

VS2005 Team Test 数据驱动的unit test

Filed under: Visual Studio

1.测试数据放在数据库中.
在测试方法的属性窗口中设置 connection string 和data table name
  [TestMethod]
  [Owner("Mark Michaelis")]
  [TestProperty("TestCategory", "Developer"), DataSource("System.Data.SqlClient", "Data Source=.\\SQLEXPRESS;AttachDbFilename="myTestData.mdf";Integrated Security=True", "LogonInfoTest", DataAccessMethod.Sequential)]
  public void ChangePasswordTest()
  {
     //得到测试数据
     string userId = (string)TestContext.DataRow[(int)Column.UserId];
     string password = (string)TestContext.DataRow[(int)Column.Password];
     bool isValid = (bool)TestContext.DataRow[(int)Column.IsValid];

     LogonInfo logonInfo = new LogonInfo(userId, "P@ssw0rd");

     if (!isValid)
     {
        Exception exception = null;
        try
        {
           logonInfo.ChangePassword( "P@ssw0rd", password);
        }
        catch (Exception tempException)
        {
           exception = tempException;
        }
        Assert.IsNotNull(exception, "The expected exception was not thrown.");
        Assert.AreEqual<Type>( typeof(ArgumentException), exception.GetType(),"The exception type was unexpected.");
     }
     else
     {
        logonInfo.ChangePassword("P@ssw0rd", password);
        Assert.AreEqual<string>(password, logonInfo.Password, "The password was not changed.");
     }
  }

2.测试数据方法Excel文件中
    [TestMethod()]
    [DeploymentItem("EmailData\\EmailData.xls")]  //将excel文件部署到测试程序所在的目录,似乎不必要
    [DataSource("System.Data.Odbc","Dsn=Excel Files;dbq=D:\\TestData.xls;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5", "Sheet1$", DataAccessMethod.Sequential)]
    public void MyFunctionTest()
    {
        //得到测试数据
        string testData = TestContext.DataRow[0].ToString();
        …
    }

3.使用配置文件
测试工程的app.config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </configSections>
      
        <connectionStrings>
            <add name="MyJetConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\testdatasource.mdb; Persist Security Info=False;" providerName="System.Data.OleDb" />
            <add name="MyExcelConn" connectionString="Dsn=Excel Files;dbq=data.xls;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5" providerName="System.Data.Odbc" />
        </connectionStrings>
       
        <microsoft.visualstudio.testtools>
            <dataSources>
                <add name="MyJetDataSource" connectionString="MyJetConn" dataTableName="MyDataTable" dataAccessMethod="Sequential"/>
                <add name="MyExcelDataSource" connectionString="MyExcelConn" dataTableName="Sheet1$" dataAccessMethod="Sequential"/>
            </dataSources>
        </microsoft.visualstudio.testtools>
    </configuration>

测试代码:
    [TestMethod()]
    [DeploymentItem("MyTestProject\\testdatasource.mdb")]
    [DataSource("MyJetDataSource")]
    public void MyTestMethod()
    {
    int a = Int32.Parse(context.DataRow["Arg1"].ToString());
    int b = Int32.Parse(context.DataRow["Arg2"].ToString());
    Assert.AreNotEqual(a, b, "A value was equal.");
    }

    [TestMethod()]
    [DeploymentItem("MyTestProject\\data.xls")]
    [DataSource("MyExcelDataSource")]
    public void MyTestMethod2()
    {
        Assert.AreEqual(context.DataRow["Val1"], context.DataRow["Val2"]);
    }

个人认为:DeploymentItem

参考

Strengthening Visual Studio Unit Tests(by John Robbins)
http://msdn.microsoft.com/msdnmag/issues/06/03/Bugslayer/

演练:使用 Visual Studio Team Test 进行单元测试
http://www.microsoft.com/china/msdn/library/langtool/vsts/vstsunittesting.mspx?mfr=true

演练:使用配置文件定义数据源 
http://msdn2.microsoft.com/zh-cn/library/ms243192.aspx

DeploymentItemAttribute
http://msdn2.microsoft.com/zh-cn/library/ms245570.aspx

May 19, 2006

VS 的 Build Events

Filed under: Visual Studio

在vs2003 和2005中都支持了Build Events, 但是2003只支持单行的命令,而2005可以支持多行命令.

要想在2003中执行多行命令,只能把命令写在一个批处理文件中,然后通过调用批处理来执行.

1.在Solution explorer中用context meun查看project的property.

2.选择Build Events,可以看到Pre-build 和Post-build event command line,以及运行Post-build event 的条件

//——————————————————

用法收集

1.build完后修改build产物的名字(后缀),并覆盖已有的同名文件.

copy $(TargetFileName) $(TargetName).XXX y

2. 调用外部命令或批处理:

call "C:\Program Files\XXX.exe"

3. 条件判断:

IF NOT $(ConfigurationName) == Release GOTO end

    call "C:\Program Files\XXX.exe" $(ProjectDir)$(TargetName).cvp

:end

4.web project 自动部署

copy     $(TargetDir)*.*     \\MyServer\MyService\bin
copy     $(ProjectDir)*.ascx     \\MyServer\MyService

//——————————————————

Macro收集

$(DevEnvDir)

$(ProjectDir)

$(BuiltOuputPath)

$(ConfigurationName)

$(TargetName)  不含扩展名

$(TargetFileName)  包含扩展名

MSDN中的 Pre-build Event/Post-build Event Command Line Dialog Box 一节有所有的Macro

May 14, 2006

VS2005的Code Snippets

Filed under: Visual Studio

1.如何使用

可以使用菜单: Edit->ItelliSencse->Insert Smnippet 或使用Context meun :Insert Snippet也可以使用快捷键:Ctrl+K,Ctrl+X

2.使用很简单,关键是可以定制.使用菜单Tools->Code Snippet Manager可以看到Code Snippet所在的路径.

C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#

所有的code snippets文件都是xml格式,并以.snippet结尾

文件中有两个核心的节点用来实现功能

<Header>节点用来描述code snippet的title,快捷键,描述,比如using.snippet

<Header>
   <Title>using</Title>
   <Shortcut>using</Shortcut>
   <Description>Code snippet for using statement</Description>
   <Author>Microsoft Corporation</Author>
   <SnippetTypes>
    <SnippetType>Expansion</SnippetType>
    <SnippetType>SurroundsWith</SnippetType>
   </SnippetTypes>
  </Header>

<Snippet>用来描述要生成的code,以using.snippet为例:

它会生成如下代码

using(resource)
{
 
}

用户可以把resource替换为自己的代码,xml中的描述如下

<Snippet>
   <Declarations>
    <Literal>
     <ID>resource</ID>
     <ToolTip>Resource to use</ToolTip>
     <Default>resource</Default>
    </Literal>
   </Declarations>
   <Code Language="csharp"><![CDATA[using($resource$)
 {
  $selected$ $end$
 }]]>

   </Code>
  </Snippet>

<Literal>部分定义了可替换的部分的id和default

[!CDATA]部分定义了要生成的代码模板,

参考资料

Code Snippets in Visual Studio 2005 讲解Code Snippets的使用和自定义,并提供了一个例子

Advanced Basics: IntelliSense Code Snippets — MSDN Magazine, April 2006

文章中的附件提供了几个例子,值得参考,同时还提供了几个Code Snippet编辑器的地址,用到时再看吧

 MSDN Code Snippet Schema Reference






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham