Category Archives: Visual Studio

Start Two Project Simultaneously

In Investigating message queues with RabbitMQ and ActiveMQ, I came across a problem that I’ve never considered before. Starting two projects at the same time.

The well-known (at least to me) way of doing this was to start the start-up project, and then right-click the second project, and select Start New Instance:

2proj

However, this is laborious when you’re constantly starting both projects. So, the alternative is to right click the solution, and select Set StartUp Projects… :

2proj2

Then you can select to start multiple projects:

2proj3

A small thing, but saves a lot of time.

Now using Visual Studio 14 CTP

I was previously using VS2013, but after running 14 just once, I saw no reason to go back. I thought I’d jot down some notes on my experience of this update. A quick caveat though: VS14 is a CTP, so if you’re thinking about using it to maintain the code for your nuclear reactor, then probably don’t.

Faster

Okay, so this is my perception. I’m working on a personal project on the train to and from work. VS14 loads almost a station before VS2013 did. Now, if that’s not a fair and accurate benchmark, I don’t know what is!

Debugging

One particularly cool feature is that you can see the CPU execution time for previous statement during debugging. Typically, this is a meaninglessly low figure of x milliseconds; but occasionally it shows an unexpectedly high figure.

This can be dangerous, because if you saw a statement that took 30ms, which executed once when the user presses a button in your app, you might think nothing of it… unless all the other statements take 2ms. At this point, you might spend 1/2 hour trying to work out what the bottleneck is. You might even find it: and speed up your app by 28ms.

Refactor

Shift-Alt-F10 on a non-existent method now gives you a preview of what it’s about to do. Possibly not the most useful feature in the world to be honest, but if you want a field and it tries to create a property then you know (obviously, if you’d just read the description of what it will create, that would also tell you). The Using statement tells you where it will create the statement:

preview

However, I can’t find any way you can affect the preview – which would have been a nice feature; for example, say you wanted to create a public field rather than internal; or, you wanted to define a constant and give it a constant value.

Light bulbs now appear next to potential refactoring. One example was an unnecessary using statement I had. It had turned grey; I didn’t understand this until I noticed that a light bulb had appeared next to it, which helpfully informed me that I didn’t need the statement.

Also, code analysis seems to be an opt-in thing now – rather than the previous version which seemed to constantly kidnap whichever tab it was on.

It is still a CTP

Line numbers were turned on in VS2013 and were off in 14.

Add a settings file from another project (VB.NET)

I recently asked this question on Stack Overflow and, although the answer I got was correct, I thought I would write it up so that a clearer explanation was available for when I forget that I asked in the first place.

Here’s the link to the SO question (as I certainly wouldn’t want to claim credit for the solution): http://stackoverflow.com/questions/20427328/sharing-settings-file-between-projects-in-vs2013

I believe that the process for C# is different, and will try to cover that in a future post.

Disclaimer

If you do read the question, you’ll see that it was suggested to create the settings file in a single library and then expose that through a public method. I do agree that this would be the best way to do things. I’m not even saying that the way here is a good way to do things. However, I was in a position where it was the only feasible way to do things, given time constraints and project architecture. I intend, in the future, the refactor, and to have just such a library of settings. If you have time do do this now, or if you haven’t yet created your settings file then I would strongly suggest you go down this route and NOT read on.

Otherwise, read on

Okay, if you’re still reading then you’re either in the same position I was, or you didn’t read the disclaimer.

Adding a Settings file as a link

In the project that you wish to add the settings file, first, delete any existing settings files from inside (or outside) the “My Project” folder. Note that by default, “Show All Files” is turned off, and this can hide the “My Project Folder”, so make sure it’s on:

ShowAllFiles

MySettings

Now that’s deleted, selected the project and select “Add Existing Item”, and in the dialog that appears, find your settings file; then, and this is the important part, select “Ass as Link”:

AddAsLink

Okay, now you have a settings file from another project. Now you need to set the namespace and the custom tool. They should look like this:

SettingsSettings

Finally, you need to manually tell the settings file to generate itself by right-clicking, and selecting “Run Custom Tool”.

Conclusion and Caveat

One of the reasons that this is a bad idea is the last step. Although you are linking to the settings file, you need to manually generate each time.

So, it’s not a good way to do things, but if you need it, it does work.