SnagIt免费注册
SnagIt 7.2.5免费注册地址:http://www.techsmith.com/snagit/ukdn.asp
SnagIt 7.2.5下载地址:http://www.oldapps.com/OldApps/SnagIT/SnagIt725.exe
遗憾的是SnagIt 7.2.5的安装程序在Vista上无法安装.
SnagIt 7.2.5免费注册地址:http://www.techsmith.com/snagit/ukdn.asp
SnagIt 7.2.5下载地址:http://www.oldapps.com/OldApps/SnagIT/SnagIt725.exe
遗憾的是SnagIt 7.2.5的安装程序在Vista上无法安装.
1.设置VMPlayer的Ethernet为Bridged模式.
Bridged模式下VM会象内一台独立的机器.
NAT模式会用到VMWare DHCP Service来模拟一个DHCP Server为VM分配IP,VM会通过
一个虚拟设备VMnet8(VMWare NAT Service)来连接到Host和外界网络.
Host-Only模式和NAT很象,唯一的不同就是没有用到NAT服务,无法访问外界网络,Host和
VM通过VMWare Network Adapter VMnet1这块虚拟网卡通信.
2.在VM中执行System-config-network
设置使用DHCP自动获得IP,自动获得DNS信息, 指定DNS server, 指定hostname(hhFedora).
或修改etc/resolv.conf
3. service network restart
很重要!
现在就何以通过机器名hhFedora来访问VM了.
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
A new tool come with .NET SDK 3.0
C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\fdbrowser.exe
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.
装完了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
Code Smith应用
在我们的project中,对于一个web service要进行3个地方的处理
1.asmx file,比如GCRecommendWebSiteManagementService.asmx.vb, 提供web methods
<System.Web.Services.WebService(Namespace:=”http://tempuri.org/“)> _
Public Class GCRecommendWebSiteManagementService
Inherits BaseService
…
<WebMethod(), System.Web.Services.Protocols.SoapHeader(”TokenValue”)> _
Public Function GetAllRecommendWebSite() As DataSet
end Function
end Class
2.内部逻辑class, 比如GCRecommendWebSiteManagementControl.vb
Public Class GCRecommendWebSiteManagementControl
Inherits BaseControl
Public Function GetAllRecommendWebSite() As DataSet
…
End Function
end class
3.在Client 端提供proxy 比如GCRecommendWebSiteManagementServiceProxy.vb
<System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute(”code”), _
System.Web.Services.WebServiceBindingAttribute(Name:=”GCRecommendWebSiteManagementServiceSoap”, [Namespace]:=”http://tempuri.org/“)> _
Public Class GCRecommendWebSiteManagementServiceProxy
Inherits BaseProxy
<System.Web.Services.Protocols.SoapHeaderAttribute(”TokenValue”), _
System.Web.Services.Protocols.SoapDocumentMethodAttribute(”http://tempuri.org/GetAllRecommendWebSite“, RequestNamespace:=”http://tempuri.org/“, ResponseNamespace:=”http://tempuri.org/“, Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
Public Function GetAllRecommendWebSite() As System.Data.DataSet
Dim results() As Object = Me.Invoke(”GetAllRecommendWebSite”, New Object(-1) {})
Return CType(results(0), System.Data.DataSet)
End Function
Public Function BeginGetAllRecommendWebSite(ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke(”GetAllRecommendWebSite”, New Object(-1) {}, callback, asyncState)
End Function
Public Function EndGetAllRecommendWebSite(ByVal asyncResult As System.IAsyncResult) As System.Data.DataSet
Dim results() As Object = Me.EndInvoke(asyncResult)
Return CType(results(0), System.Data.DataSet)
End Function
end Class
三部分代码大同小异,目前的做法是copy-post-modify,不好.
我想可以通过下面的方法来自动生成代码:
1. 在GCRecommendWebSiteManagementControl.vb中定义出一个web service所有方法的原型.
2. 在CodeSmith 模板文件执行时利用CodeDomProvider.CompileAssemblyFromSource动态build这个文件,
生成一个assembly,再遍历这个assemlby中的type,type中的method, 利用code dom 就可以生成对应的代码.
注意由于vb会在build一个assembly时加入诸如My.MyApplication,My.MyComputer的class,同时一个
class也会从object继承一些method,所以又需要定义一个attribut来标识需要生成代码的type和
method.
收获
1.使用了自定义的assembly(包含标识type和method的attribute)
2.使用子模板,根据不同的语言生成代码.
3.使用code behind文件,把大量的逻辑放在.cs文件中
4.复习了codedom,
VBCodeProvider.CreateGenerator 已被废弃,现在的用法是:
CodeDomProvider codeProvider = CodeDomProvider.CreateProvider(”VisualBasic”);
codeProvider.GenerateCodeFromMember(cmm, sw, new CodeGeneratorOptions());
5.CodeDom动态编译
//——-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
实验:
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 (一度出现,现在不见 )
有这样的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
1. DIY一个EXE.
http://code.mattgriffith.net/UpdateVersion/
http://code.mattgriffith.net/UpdateVersion/UpdateVersion-src-1.2.zip
用在Nant中修改AssemblyVersion
<project name=”ExecTest” default=”test”>
<target name=”test” description=”tests using exec to run UpdateVersion.exe”>
<echo message=”** Running UpdateVersion.exe.”/>
<exec program=”UpdateVersion.exe” commandline=”-b MonthDay -s 2002-01-21 -i Input.txt -o Output.txt” verbose=”true” failonerror=”true” />
<echo message=”** End of Tests”/>
</target>
</project>
Input.txt是一个包含AssemblyVersion的文本文件
也可以用在VS中;
Tools -> External Tools… -> Add :
Title: Update Version Number
Command: UpdateVersion.exe
Arguments: -b MonthDay -s 2002-11-23 -i “AssemblyInfo.cs” -o “AssemblyInfo.cs”
Initial directory: $(ProjectDir)
Use Output window: Checked
2.NAntContrib 中的 <version> task
<Version BuildType=”increment”
RevisionType=”increment”
Path=”$(BuildNumberFile)”
WriteVersionInfo=”true”
VersionInfoPath=”$(VersionInfoFile)”>
<Output TaskParameter=”BuildNumber” PropertyName=”BuildNumber”/>
</Version>
3. 在NAnt中使用脚本
<script language=”C#”>
<imports>
<import name=”System.Globalization” />
<import name=”System.Threading” />
</imports>
<code><![CDATA[
[Function(”test-func”)]
public static void ScriptMain(Project project)
{
Version version = new Version(project.Properties[”build.version”]);
int major = version.Major;
int minor = version.Minor;
int build = version.Build;
int revision = version.Revision;
if (build == -1)
{
DateTime start = Convert.ToDateTime(project.Properties[”startdate”]);
Calendar calendar = Thread.CurrentThread.CurrentCulture.Calendar;
int months = ((calendar.GetYear(DateTime.Today)
- calendar.GetYear(start)) * 12)
+ calendar.GetMonth(DateTime.Today)
- calendar.GetMonth(start);
int day = DateTime.Now.Day;
build = (months * 100) + day;
}
if (revision == -1)
{
TimeSpan difference = DateTime.Now.Subtract(DateTime.Today);
revision = (int)(difference.TotalSeconds / 10);
}
version = new Version(major, minor, build, revision);
project.Properties[”build.version”] = version.ToString();
}
]]></code>
</script>
<echo message=’${test::test-func()}’/>
4. 使用macor, 使用ProjectItem来查找AssemblyInfo,然后进行替换.
Auto Increment Build Numbers for C# Projects in VS.NET 2003
http://www.biasecurities.com/blogs/jim/archive/2003/10/08/166.aspx
Managing AssemblyVersion
http://weblogs.asp.net/sjoseph/archive/2004/02/19/76277.aspx
参考
Using Open Source .NET Tools for Sophisticated Builds
Versioning with NAnt
http://geekswithblogs.net/flanakin/archive/2004/08/16/9763.aspx
http://nant.sourceforge.net/release/latest/help/tasks/script.html
http://nant.sourceforge.net/release/latest/help/tasks/script.html
核心就是使用<script>
<script language=”C#” prefix=”test” >
<code>
<![CDATA[
[Function(”test-func”)]
public static string Testfunc( )
{
return “some result !”;
}
]]>
</code>
</script>
<echo message=’${test::test-func()}’/>
最酷的是用c#定义一个 custom task 并调用.
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>
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
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
非常有用!
出自
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>
!
TestDriven的主要功能:
1.Run Tests
可以在VS中直接运行unit test 代码,并将结果显示在Out put窗口中.
2.Test With->Debugger
debug Test 代码
http://www.mertner.com/confluence/display/MbUnit/Home
MbUnit : Generative Unit Test Framework
在使用vs2005编辑网页时,选中一个tag,再使用右键菜单上的”Synchronize Docuent Outline”可以在Document OutLine中构造一个html tag树.
出自
SOS: It’s Not Just an ABBA Song Anymore(John Robbins)
http://msdn.microsoft.com/msdnmag/issues/03/06/Bugslayer/
源码:
//——————————————————–
using System ;
using System.Diagnostics ;
namespace ExceptApp
{
enum Days { Sat = 1 , Sun , Mon , Tue , Wed , Thu , Fri } ;
class DoSomething
{
public void Doh ( String StrParam , Days ValueParam )
{
Console.WriteLine ( StrParam ) ;
Console.WriteLine ( ValueParam.ToString ( ) ) ;
throw new ArgumentException ( "Throwing an exception" , "x" ) ;
}
public void Reh ( int i , String StrParam )
{
Console.WriteLine ( "Reh = " + i ) ;
String s = "Tommy can you see me? " + StrParam ;
Days e = Days.Fri ;
Doh ( s , e ) ;
}
public void Mi ( Object o )
{
Console.WriteLine ( "Mi = " + o.ToString ( ) ) ;
String LocalStr = "Can you see me?" ;
Reh ( 0x42 , LocalStr ) ;
}
public void Fa ( )
{
Mi ( this ) ;
}
}
class Class1
{
static void Main(string[] args)
{
try
{
DoSomething x = new DoSomething ( ) ;
x.Fa ( ) ;
}
catch
{
}
}
}
}
1. 何让WinDbg 拦截CLR Exception
使用菜单Debug->Event Filter打开Dialog
Click "Add"
enter "0xE0434F4D"
Select "Enabled" in the Execution group box
select "Not Handled" in the Continue group box
2. 使用 !thread 显示进程或一个dump文件中所有的managed线程
ThreadCount: 2
UnstartedThread: 0
BackgroundThread: 1
PendingThread: 0
DeadThread: 0
Hosted Runtime: no
PreEmptive GC Alloc Lock
ID OSID ThreadOBJ State GC Context Domain Count APT Exception
0 1 188 00181148 a020 Enabled 013c4b6c:013c5fe8 0014f238 0 MTA System.ArgumentException (013c4ad0)
2 2 94c 0018ae58 b220 Enabled 00000000:00000000 0014f238 0 MTA (Finalizer)
OSID为 win32 thread id
Domain 线程所在的app domain
Exception 可能包含多种含义, 以上的信息表明1号线程引发了ArgumentException, 2号线程是Finalizer
这个字段的值还可能是 (Threadpool Worker), (Threadpool Completion Port), or (GC),这些
都是.net的执行线程.
3. 使用Windbg的 ~ 系列命令
~ : 显示所有的线程
~* : 显示所有的线程
~. : 显示当前线程
~# : 引发异常的线程
~2 : 2号线程
使用~会显示
. 0 Id: b64.188 Suspend: 1 Teb: 7ffde000 Unfrozen
1 Id: b64.a14 Suspend: 1 Teb: 7ffdd000 Unfrozen
2 Id: b64.94c Suspend: 1 Teb: 7ffdc000 Unfrozen
可见, 进程中除了2个.net线程,还存在一个win32线程.
4. 使用 !clrstack (或!dumpstack)
!clrstack -a 查看所有信息,包括参数和局部变量
!clrstack -l 查看局部变量
!clrstack -p 查看参数
~*e!clrstack 查看所有线程的调用栈.
使用 !clrstack -a 显示
OS Thread Id: 0x188 (0)
ESP EIP
0012f350 7c81eb33 [HelperMethodFrame: 0012f350]
0012f3f4 00df02e7 ExceptApp.DoSomething.Doh(System.String, ExceptApp.Days)
PARAMETERS:
this = 0x013c1c44
StrParam = 0x013c3f18
ValueParam = 0x00000007
0012f418 00df0237 ExceptApp.DoSomething.Reh(Int32, System.String)
PARAMETERS:
this = 0x013c1c44
i = 0x00000042
StrParam = 0x013c1c6c
LOCALS:
<CLR reg> = 0x013c3f18
0x0012f41c = 0x00000007
0012f438 00df01a0 ExceptApp.DoSomething.Mi(System.Object)
PARAMETERS:
this = 0x013c1c44
o = 0x013c1c44
LOCALS:
0x0012f438 = 0x013c1c6c
0012f450 00df0134 ExceptApp.DoSomething.Fa()
PARAMETERS:
this = 0x013c1c44
0012f458 00df00b8 ExceptApp.Class1.Main(System.String[])
PARAMETERS:
args = 0x013c1c34
LOCALS:
0x0012f458 = 0x013c1c44
0012f69c 79e88f63 [GCFrame: 0012f69c]
以上内容对应于.net2.0 和原文中有所不同.
5. 使用dd 0x**** 可以查看内存中的值
6. !DumpMT [-MD] <MethodTable address>
显示位于某个地址的 method table的信息, 每个managed object都会有个method table
7. !DumpClass 显示class所有信息
8. !Dumpmodule
9. !Dumpobject
对于一个static 变量,会显示domain 和 静态变量在domain中位置, 这些信息被>>和<<扩起.
790fa3e0 4000099 10 System.String 0 shared static Empty
>> Domain:Value 0014f238:790d6584 <<
10.!DumpStackObjects 显示当前线程的堆栈上的所有对象.
//—-SOS.dll 的位置
%windir%\Microsoft.NET\Framework\<version>\
Documnet
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Tool Developers Guide\Samples\sos
.NET 2.0中这个目录不见了.
//—-让WinDbg加载SOS
当打开一个.net 可执行程序windbg6.5会自动加载SOS,如果需要手动加载,有如下方法
方法1:配置系统环境变量,让搜索路径指向系统.NET Framework的安装目录,既sos.dll所在目录
set PATH=%PATH%;C:\WINDOWS\Microsoft.NET\Framework\<Version>
然后使用.load SOS 加载
方法2. 加载某个特定的sos
.load <full path to sos.dll>
方法3.
.extpath command sets or displays the extension DLL search path.
方法4.
.loadby sos mscorwks
debugger 会加载模块mscorwks所在路径下的sos
方法5.
直接使用形如!DLLName.ExtensionCommand 的命令,如果扩展dll没有被加载,debugger会加载之.
在windbg6.5的安装目录下也有一个sos.dll
C:\Program Files\Debugging Tools for Windows\clr10
加载和使用方法如下:
.load clr10\sos
!clr10\sos.help
//—-相关命令
.load sos
加载SOS
.chain
list extensions dlls,以确认SOS是否正确加载
.setdll sos.dll 把SOS设置为default extension.
lm
查看有哪些模块被载入内存
//—–实验
用Windbg打开一个.net 可执行程序(ctrl+E), WinDbg会自动break到程序入口(如果attach到一个程序上,则
立即break),此时,mscorwks尚未被加载,如果在此时加载了SOS,SOS中的命令还无法使用.F5让程序继续运行,
这次WinDbg会自动break到,此时使用lm命令可以看到被加载的module,其中包含了mscorwks.dll,此时SOS中的命令
才可使用
参考
SOS: It’s Not Just an ABBA Song Anymore(John Robbins)
http://msdn.microsoft.com/msdnmag/issues/03/06/Bugslayer/
Mini Dump Snapshots and the New SOS(John Robbins)
http://msdn.microsoft.com/msdnmag/issues/05/03/Bugslayer/default.aspx
SOS Debugging of the CLR, Part 1
http://blogs.msdn.com/jasonz/archive/2003/10/21/53581.aspx
用WinDbg探索CLR世界
http://flier.cnblogs.com/archive/2004/07/08/22313.html
深入探索.NET框架内部了解CLR如何创建运行时对象
http://www.microsoft.com/china/MSDN/library/netFramework/netframework/JITCompiler.mspx?mfr=true
如何:使用 SOS
http://msdn2.microsoft.com/zh-cn/library/yy6d2sxs.aspx
SOS Debugging Extension (SOS.dll)
http://msdn2.microsoft.com/en-us/library/ms404370.aspx
//—–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
//–Symbol的分类
private : 包含最完整的调试信息,如变量,函数信息
retail : 次之,不包含变量信息
export : 用处不大
//–设置symbol path的3种方法
1. 设置_NT_SYMBOL_PATH环境变量(要在运行windbg前设置)
2. 使用菜单 File->Symbol File Path或通过快捷键 ctrl+s
3. 使用.sympath 命令
C:\WINDOWS\Symbols\dll;
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\symbols;
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\symbols;
SRV*C:\MyLocalSymbols*http://msdl.microsoft.com/download/symbol
其中最重要的是:
SRV*C:\MyLocalSymbols*http://msdl.microsoft.com/download/symbol
这一句会使Windbg在需要Symbol时检查C:\MyLocalSymbols路径,如果没有找到所需的Symbol,
Windbg会从http://msdl.microsoft.com/download/symbol把所需的Symbol下载到C:\MyLocalSymbols
注意:http://msdl.microsoft.com/download/symbols不能通过ie访问,只有MS的debug工具可以访问.
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
在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
1.首先需要下载NAntContrib,把所有的文件和NAnt的执行文件放在一起.
2.NAntContrib会调用VSS的客户端来get源代码,如果不想安装VSS,可以
只copyVSS安装路径下的SSAPI.dll 和SSUS.dll,并注册ssapi.dll,命令如下:
regsvr32 ssapi.dll
3.script
——–get:
<vssget
user="myusername"
password="mypassword"
localpath="myLocalpath"
recursive="true"
writable="true"
dbpath="myVSS\srcsafe.ini"
path="$/MyProduct"
/>
——-checkout:
<vsscheckout
user="myusername"
password="mypassword"
localpath="myLocalpath"
recursive="true"
writable="true"
dbpath="myVSS\srcsafe.ini"
path="$/MyProduct"
/>
注意localpath只能指定为本地路径
path,可以制定为vss中的路径或某个文件
——–checkin:
<vsscheckin
user="myusername"
password="mypassword"
localpath="myLocalpath"
recursive="true"
writable="false"
dbpath="myVSS\srcsafe.ini"
path="$/MyProduct"
comment="NAnt checkin"
/>
也可以直接使用vss来进行操作:
比如get:
<exec program="${vss_path}\ss.exe" commandline="GET ${path_vss} -R -I-Y -O- -GTM -GL${path_local}"
output="my.log">
</exec>
只是那一堆的参数让人有点头大.
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编辑器的地址,用到时再看吧
Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham