Perfil de PaulioIT BytesBlogListasScraps Ferramentas Ajuda

Blog


24 de julho

Listing the files in a Changeset

I've been trying to do this off an on for a while and finally tracked it down...
 
To list the files in a changeset;

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE>tf changeset /i 27880

 

To show the dialog in a separate process so you can carry on using Visual Studio just omit the /i
07 de julho

Problems with locked DLLs when compiling in Visual Studio

For some, as yet to be understood, reason after a few debug sessions some of the dependant DLLs become locked by Visual Studio and the build stage cannot overwrite the DLLs. Today I finally decided to see if anyone else was have the same problem and found this in Gary Farr's blog (copied in case the blog becomes unavailable);
 
Final solution:
VS basically locks the file and you cannot use third party resources to unlock it.  Therefore, just use VS!  In the Properties of a project in your IDE you have Buld Events.  Basically, you can write scripts during pre and post builds of a project.  I added these two lines in the pre-build event command line, which basically unlocks the dll within Visual Studio.

IF EXIST $(TargetPath).LOCKED  (del $(TargetPath).LOCKED) ELSE (IF EXIST $(TargetPath) (move $(TargetPath) $(TargetPath).LOCKED))
 
08 de março

Using IIS in Vista to access your Visual Studio web site project

Developing in Vista certainly presents the odd challenge. Recently I've started to develop applications using Live Mesh and I wanted to test out Delegated Authentication which involves running a web site under IIS. Now I'm not used to IIS 7 so after the initial shock of a new UI I setup the required virtual directory and ran my web site. However, I kept getting a rather strange error message;

The requested page cannot be accessed because the related configuration data for the page is invalid.

At first I took that to mean I'd corrupted my web.config file but no that all seemed fine. I eventually tracked down a Test Settings button in IIS. This showed a big warning triangle saying that it couldn’t ensure the site identity would be authorised to access the disk folder. Once I’d set an appropriate user to access the folder everything worked fine.

To access the Test Settings button;

Open IIS->Navigate to your site->Basic Settings (in the right pane)->Test Settings->Click on any line with a warning triangle and read the explanation.

27 de fevereiro

Visual Studio freezing/crashing with Team System Foundation Server

Finally made the switch from Visual Source Safe to Team System Foundation Server today but as luck would have my machine didn't enjoy the experience. My colleagues machine was running fine, the speed difference in opening a solution or checking in/out was impressive. My machine would just sit there endlessly waiting for the check-in to work until finally I killed it off. It then occurred to me that I hadn't connected to the Foundation Server in my Team Explorer. Once connected everything seems to be running fine. So my tip is, ensure you've connected via Team Explorer before you attempt to use the Source Control.

16 de novembro

Easy way to redirect ASP.NET trace to Visual Studio Output Window

The ASP.NET trace information can be very useful, however there are cases when you don't want (or can't - partial rendering) have the trace information rendered on the page. However, all is not lost, you can redirect the information to VS' output window by changing (or adding) the web.config trace element with writeToDiagnosticsTrace, e.g...
<trace writeToDiagnosticsTrace="true" enabled="true" pageOutput="false" requestLimit="20" />
 
28 de abril

Profiling Web Projects in VS2008

I had a number of problems using VS2008's profiler today so I thought I'd share my finding to lesson the suffering for others!

I'm working on a solution with a large number of projects all starting from a web project. All of the projects are strongly named. I wanted to use 'instrumentation' in order to get the most accurate statistics I could gather.

Problem 1.
When I first tried to launch the profiler it complained that my project was signed. The problem is that instrumentation requires the profiler to inject code into my DLL therefore changing the DLL, thus breaking the signature of the code. Happily it tells you that you can use an instrumentation step to re-sign the DLL.

Problem 2.
Ok, now luckily I'd been here before (and blogged how) so I added the re-sign code and tried again. So it launched (using IIS rather than Cassini) and I navigated around the site and finished the session. However the report was gibberish and contained hex numbers and guids where function and DLL names should be, not good. So it looks like a problem with the pdbs. After setting a number of pdb locations and ensuring the pdbs were serialized correctly I finally decided that the injection of code was upsetting the pdb so I switched off signing for every project.

Problem 3.
Still gibberish. Odd. I went to the ASP net temporary files and delete the lot. Re ran it and hurray something that looks like a profile.




28 de fevereiro

Remote debugging in Visual Studio 2008

A quick post about a couple of potential gotcha's with remote debugging in VS2008.

First off, you need to use the remote debugging monitor that ships with VS2008, although they look identical the VS2005 monitor won't work with VS2008. Next problem is where to find the monitor. In VS2005 it was a separate install on the VS2005 setup disks, in VS2008 it's installed into the common IDE folder under VS2008 (...Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger\x86). You simply copy the files from there to the machine you want to monitor. As for getting it to use breakpoints and the like then it's back to the old tricks of remote debugging. Basically to make life easy it's much better to just rebuild the DLLs you're interested in and ship them to the target...saves a lot of hassle.


20 de fevereiro

Visual Studio Addins not showing

I've developed a small Add-in for Visual Studio and kept running into a rather odd problem. During the testing of the addin it would work fine, I'd see my Addin in the addin manager and I'd get a couple of new menu items showing under the tools menu. However, when I built a release version, copied the files into my VisualStudio 2008\Addins folder I could only see the Addin in the manager but not the menu items. Turns out that I just needed to get rid of the XXXFor Testing.Add file from the Addins folder. Well I renamed it to make it easier to debug later, but I certainly confused me for a while, I think the debug version should have a different name, which you can do by editing the .addin file.
 
17 de novembro

Using OneClick installed applications in Visual Studio

One of my colleagues "recently" converted a win exe tool I use from Visual Studio to be a OneClick install application. This is great since I get the latest version whenever I run the exe. However, when you add an external tool to Visual Studio you only get the choice of a very limited number of extensions. The problem is that OneClick applications are installed using an application link rather than an exe, that's hidden away from view. To solve this problem I simply created a batch/command file that launches the link, and then added the batch file as the external tool, job done.

17 de julho

ALT+SHIFT to select a rectangle of code

Every now and again I rediscover a tip when using Visual Studio, this time I was in SQL Management Studio but the tip is the same nonetheless. If you want to select a column of text (in my case it was a column of periods) then hold down ALT+SHIFT and move your mouse. It may not seem very useful now but I guarantee you'll need it at some point!

08 de julho

Team System Performance Profiler

Why is something that is so good, be so bad? My misfortune with this profiler continued today when I wanted to test a DLL...I know whoa don't try anything too tricky ;) The DLL in question is signed but the profiler must be injecting code or something because it failed complaining that DLL wasn't signed. A quick look on the web and sure enough it does de-sign it, and you're supposed to re-sign in a post instrumentation step. Ok, but what does that mean. Well to save the next person the hassle I had it is this...
<path>sn.exe -R <path to assembly> <path to key file>

I can't believe this isn't the de facto way people would performance test so why isn't that step just built in?

The next problem had me shacking my head in disbelief. I wanted to add a new project to instrument, so I clicked add and a huge non-scrolling dialog opened where my project was about 2 miles below the screen. Good grief, what a rookie error. Luckily I managed to count the number of projects and press the down arrow the corresponding number of times, press space then enter. Come on Microsoft, please test Visual Studio with decent sized projects, please!

21 de abril

A couple of File path tips in Visual Studio 2005

I thought I'd share a couple of VS tips related to file paths:

1. Copy full path from the tab
The simplest way to get the full path to a source file is to open the file in the editor and the right-click the source panes tab. One of the options is to copy the full path
2. Quick way to open another file located in the same folder as an existing  source file
When you have a number of source files opened from various locations it can be frustrating to go through the File->Open and navigation process time and again. One trick is to keep open an existing project file located in the folder you want to navigate to. When you select File->Open it will start in the same folder location as the active file in the editor.


19 de fevereiro

Using Team System Foundation Server for Source Control

Team System is a great suite of tools, providing you can afford it, for developing software. However, it does represent a significant investment to move an existing team of developers onto it. Rather than moving in a "Big bang" approach my current team are progressing in a steady rate by using all Team System editions for development and we're about to use Foundation Server's source control. What we didn't want to do was take all the process guidance, at least not yet. After some annoying problems installing the software, if ever you need to slavishly follow a readme this is it, I finally got the server running. I had been told that you cannot easily use the Source Control without taking the process guidance. Well this is true, but to a lesser extent. To use the Source Control you must create a Team Project and yes that does involve selecting a process. However, once selected you don't have to switch on any of the policies. What does that mean? Well when you check code in you do get a dialog that allows you to type in extra details, assign work items, etc but since the policies for the process aren't on, it doesn't nag or even prompt you. So effectively you have Source Control like Visual Source Safe but with all the juicy advantages of Team System's Source Control. Now to get someone else to edit my demo project and see how easy it is to work in the, "don't lock files when checked out" mode. Sounds like utopia but will probably be more like hell!

23 de janeiro

Checking out all (and only) the projects for a Solution

Visual Studio (VS2005) doesn't comes with a fair bit of Source Safe integration but it also has some annoying traits.
The default behaviour of checking out a single project is to also check out all the files within it.  Ok it only takes a few mouse clicks to stop this but it's annoying. However, this is really frustrating when you're working on a solution with 10s or 100s of projects. So I wrote a quick macro to avoid these issues, and it goes something like this...

Dim currentProject as EnvDTE.Project
for each currentProject in DTE.Solutions.Projects
    DTE.SourceControl.CheckOutItem(currentProject.FullName)
next

13 de agosto

Microsoft Expression Interactive Designer

Ran through a simple Tutorial today using the Beta of Expression Interactive Designer. It's quite an odd experience, sort of like a cross between a image tool and a traditional Windows form designer, at least as far as the UI is concerned. However, the tutorial wasn't without its problems.
 
Problem 1, "Namespace is incorrect, please change root namespace element in the project". When I ran the tutorial I got a very strange error. This shows one of the major drawbacks of this tool. Essentially what I guess had happened is that at some point I'd been forced to "Save As" and used a different name, "Fabrikum Tutorial2". Unbeknown to me this create a rootNamespace element, in the actual project file, called "Fabrikum Tutorial2". So after fishing around with the C# code produced (via notepad) it dawned on me that it was using "Fabrikum_Tutorial2", i.e. no spaces. So I manually changed the project by inserting the underscore and hurray it compiled. Now I'm not suggesting that I'm some kind of developer super hero but this tool is aimed at UI designers who shouldn't have to care about c#, that's really the point of it. So why show bizzare errors that mean nothing and can't be fixed without getting low down and dirty with the code. Oh well I guess that's Beta software.
 
Project 2. Data binding. The first example gets you to set up a number of data bound controls. However, it didn't work. The automatic synchronising between master and detail panes simply didn't happen. Opening the finished sample of the code I tried to compare the XAML produced. Now I could see differences but I had no idea how to get these changes via the designer. That's how I left it, tutorial 1 complete, but with it not working. Score another one for the Beta product, but you'd think at this late stage a simple tutorial should work.
04 de agosto

Talking about Visual Studio tips and tricks

This helps with one of my greatest peeves, that of writing too much code on one line. In the age of huge monitors and people that use freakishly small fonts the line length of code can quickly become unreadable for many users.

 

Quote

Visual Studio tips and tricks

Column Guides in Visual Studio

A lot of coding guidelines specify the maximum length for a line of code. For instance in the CLR, Microsoft like to keep lines of code under 110 characters long. Visual Studio has a feature which lets you display a vertical line at the column of your choosing to help visually see when a line is getting too long. This does involve mucking in the registry so the usual disclaimers apply.

To enable this feature, set:

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Text Editor]

"Guides"="RGB(192,192,192) 110"

The values passed to the RGB function let you specify the color of the line, and the number following tells Visual Studio at what column to display it. The

01 de agosto

Snippets and auto-stubs

A few more tips for getting the most out of Visual Studio.
 
  • Snippets from Intellisense. When you start to type in the editor you'll get the trusty intellisense drop down. If there is a snippet available then it also be shown, for example as you start to type t..r..y you'll see the "try" snippet, but how do you invoke it. After much trial and error yuo need to double tab, i.e. with the try snippet highlighted press tab twice in quick succession
  • Auto-stubs. When you're inside a function and you realise you have to going to have write another function and call it, then write the the call to the yet-to-exist function an you'll see a little block appear under the new function name. Selecting that will automatically create the skeleton code for your new function using the arguments (and datatypes).
  • Auto-add "Using". If you add a call to a component you have referenced but don't specific the full namespace and haven't yet added it to the "using" statments then a little block will appear under the component. Selecting that will auto-create the correct "using" statement
26 de junho

Navigation shortcuts

Quick tips for navigating around code in Visual Studio 2005.
 
When you select "Goto Definition" you can navigate back to the line in the calling function using one of the following...
1. CTRL-   ... move to my last position
2. CTRL * ... move to the last calling function
 
The difference between the two is that (1) will move back through every step, so if you page down twice it will page up twice for you. Whereas (2) will simply take you straight back to the previous function.
08 de junho

Converting VBScript to .net

I've recently been faced with the prospect of supporting a number of VBScripts in a product written almost exclusively in C#. So rather than continue supporting VBScript I wondered how difficult it would be to convert the VBScript to .NET?
 
So how to convert the code? The obvious answer is to either write a parser or use a commercial converter or parser language. Well I couldn't find anything (at least not cheaply) that would automatically convert the code. I also rejected the idea of writing a parser since I know from experience that the parser is easy, it's implementing all the language rules that are tricky. Now that sounds like a good reason but in reality I knew that the VBScripts I'd be supporting are all roughly the same and would only represent a small subset of the available VBScript lexicon so I didn't really want to spend the time implementing a fully blown solutions, what I needed was a fairly quick and simple answer. I decided that it was about time I learnt regular expressions and it seemed to me that this would provide me with a conversion mechanism.
 
The next problem was which .net language to choose. I spend most my day using C# but business developers don't tend to like that - again another excuse. The real reason for choosing VB.NET is that it is *very* forgiving and shares a number of functions and keywords with VBScript so should make the conversion easier. So the converter was going to go from VBScript to VB.Net and use RegEx's to do the donkey work.
 
So using the Regex component of .net I set about producing a converter.
Tasks, including the pattern used;
NB. As you'll see I'm a RegEx newbie so the patterns used tended to change as I found new ways of doing things, but hey they work.
  1. Ensure Option Explicit is removed - I don't need it so I'm dropping it from the VBScript - (?i)\s*Option Explicit
  2. VBScript functions and Subs - Pesky devils, the problem here is that function need a "As object" value and all routines really should (in my case) have their arguments prefixed with ByRef to be compatible with the VBScript.
    Find those routines - (?i)(Function|Sub)\\s*[a-z_][a-z_0-9]*\\s*[(](([\\w\\d]*)|(\\s*,\\s*[\\w\\d]*))*[)]
    Remember the name of the routine - (?i)(?<=((Function|Sub)\s*))\w*
    Get the arguments - (\((([\w\d]*)|(,\s*[\w\d]*))*)|(,\s*(([\w\d]*)|(,\s*[\w\d]*))*)
  3. So we've converted the routine declaration, but VBScript doesn't (typically) use brackets when calling a routine and VB.NET requires them, so "lucky" we remembered the names of the routines in step 2.
    Find any caller to a function that isn't already using brackets and isn't simply the assignment of the function result - string.Format(@"(?i)(?<!(Function|Sub)\s*){0}(?!(\s*=)|(\s*\())", routineName)
  4. Adding Namespaces - this one caught me out at first, it was fairly obvious that I needed to import "system" but it took a couple of scratched heads to include "Microsoft.VisualBasic", seems obvious now!
  5. The next problem was general differences in keywords and types, etc. The most common one was replacing "now()" with "DateTime.Now". This proved an interesting problem since a number of scripts contained code such as "now()-1", so converting that to "DateTime.Now-1" didn't cut it since .net can't correctly cast the integer. So (for some reason) I chose to replace those with DateSerial(0,0,x) - (?i)(?<=DateTime\.Now\s*)(-|+)\d"
    The other common problem was VBScript variables called "Return", so they needed replacing, again nothing fancy just guessed at a unique name, NB return isn't a valid exit in VBScript -
    replace...(?i)\bReturn\b", "ReturnVarX "
  6. "Set" and "Let" - so Microsoft has finally killed these off, who knew? ;) - (?i)(?<=\s)set\s*
  7. All done!

So there you go, as long as you're not guaranteeing 100% VBScript conversion and, like me, have a finite (if large) number of scripts to convert, you can probably convert them all with the minimum of fuss and a few regular expression.




26 de abril

Anti Virus and Visual Studio

The projects I work on are typically big. The frustrating thing about this is that when I "build" the project my Anti-virus tool (McAfee) constantly checks everything. It accounts for up to a 1/3 of the build time! So not only do you suffer from getting a virus, you suffer for trying to avoid them. My advice is to turn off "On-Access scan" whilst building. Far from ideal but what choice is there?