How Execute one project while editing another project in same VS .NET Solution

I have a solution with 3 projects: a console project, a windows forms project and a class library project. Actually, I'm learning WCF and the book I'm reading says to run the console application. After which I should add some code to the windows forms application and add a reference to the class library.

The thing is visual studio 2008 doesn't allow me to edit the windows project while the console application is running. The book doesn't give instructions on how to do this. Does anyone know?

Thanks
San
SanmarieAsked:
Who is Participating?
 
abelConnect With a Mentor Commented:
Maybe some of the hints below will help you further in getting this sorted. For all of it, I assumed you have "Allow edit and continue" set to On.

Edit a file of the running project
The reason that you cannot edit any file while running your main project, is because you are not in break mode (assuming you have "allow edit and continue" set to On). To get into break mode, just hit the Pause button in Visual Studio while running your main project.

Edit a file not in the running project
The reason that you cannot edit your particular file (visual studio will say "Changes are not allowed if the assembly has not been loaded.") is because it is not loaded. You can load the file in two ways:

  1. add a reference to the file into the main project and declare (at least) one variable to something from the included reference (or call a static method). This will load the other assembly. Only an Imports/using directive is not enough.
  2. use Assembly.Load("assemblyname")  to load the assembly to prevent problems with circular dependencies.
there are more ways, of course, to have your assembly loaded, but these are the easiest. But once your assembly is "in the air", you can edit as soon as you hit a breakpoint or click on Pause.

Edit a file not in the running project while not in break mode
If you want to edit a file that belongs to a project that actually is loaded, but you are not currently in break mode, you will receive the error "Changes are not allowed while code is running or if the option 'Break allproeceses when one process breaks' is disabled. The option can be enabled in Tools, Options, Debugging.". Just uncheck the mentioned option if you do want to edit while not in break mode (or just hit Pause and you can do whatever you want).

Add a reference to a project while running
As you already found out, that option is greyed out and for good reason. But, you can load a reference dynamically, if you want, using any of the techniques mentioned above. But I doubt that your textbook means that, so let's consider it a mistake in the textbook. Just make sure the reference is there before you start running. If not, let me know, and I can give you some options on how to add that reference dynamically.

Enabling Edit and Continue in ASP.NETThis is off-topic, but because there are so many posts on blogs that tell a wrong story about this, I figured I'd mention this here because it is related. To enable it, it is not enough to have it in your Options, you must also enable it inside the Project Properties under tab "Web", option "Enable Edit and Continue"

-- Abel --
0
 
HalfAsleepCommented:
You can "run" an application from visual studio and keep editing anything in visual studio.  You can also start a debug session of one of the projects and still keep editing in the visual studio.  You cannot start 2 debug sessions though.  What is the exact wording from the book?
0
 
SanmarieAuthor Commented:
The wording in the book is: "Test the solution by compiling and running the host (the console application) first and then the Client (the windows application)."

I can't run an application in visual studio and keep editing in it. Is there some setting that I need to set? I even went to the properties of the solution and set the host to "Single Startup Project" and "Multiple startup projects" where I set it to "Start without debugging"

Thanks
San
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
HalfAsleepCommented:
Why do you need to edit it?  I think what the book wants you to do, is to run both the server and the client.  You can achieve this in visual studio by selecting "start without debugging" from the "debug" menu.

It does not sound to me like the book wants you to edit while you are running, merely running the two together to test them.  And you _can_ run an application and edit it at the same time in visual studio.  If you are deugging however, you will not be able to edit the code at the same time.

You have to compile both projects, and then run them both, the host first, and then the client.
0
 
HalfAsleepCommented:
And of course, like you have already discovered, you can also tell visual studio to start more than one project, through the solution properties.  You should be able to keep editing in visual studio, even though you have started your two applications, as long as you don't start them in debug mode.
0
 
SanmarieAuthor Commented:
Yes, I know about the option where you can tell visual studio to start more than one project through the solution properties. I cannot edit in Visual Studio when any of the projects is running. Here is another instruction from the book:

1. Start by running the Host project so that you can generate proxies for each service.
2. Go to the client project in solution explorer and right click the project to add a Service reference (This is greyed out for me).
3. Next add code to the client project to invoke each operation as shown below ...
4. Compile and test the client application.

So the instructions are telling me that I should first run the host project. Next, I should  edit the client project which I cannot do. Then finally I should compile and run the client project.

Thanks
San
0
 
Aleksei_MalkovConnect With a Mentor Commented:
HI,
the point is you are going to modify in VS running solution.
You can create second solution for client project, and open 2 VS instances one for every solution. One solution for Host - another for Client. (Don't forget remove client project from Host's solutions).

This way you'll be able develop/debug both projects

The second way is to launch Host project from command line and develop client only. But when you build the solution that contains running Host project you'll have errors from VS that it cannot overwrite exe or dll.

Thus I'd suggest to have 2 different solutions, and if you don't develop the Host - launch it from command line.
0
 
HalfAsleepConnect With a Mentor Commented:
It should be possible to run one project in the solution, and edit/debug a second one.   Running a project from the command line or from visual studio is the same thing.  Visual studio keeps no "connection" to the executable if you run it without debug.  But I agree with Aleksei, having 2 solutions, so that you can run 2 visual studio instances, is one way of making sure you can edit the other project, even while one of them is in debug mode.
0
 
abelCommented:
Btw, I would like to add that it is not necessary (though handy) to open another Visual Studio instance to run two or more programs. Just rightclick your project and select Debug > Start New Instance. This also works if you want to test how your program reacts when more than one instance of the program is around.

By default, breaking (hitting Pause or a breakpoint) would break all processes. The option "Break all processes when one process breaks" as mentioned above can be set to prevent that from happening and to keep other processes responsive when you hit a breakpoint.

If you click the Pause button or Debug > Pause, this will break all running processes, regardless of the setting under Options. To break only a certain process, select from the main menu Debug > Windows > Processes and in the Processes window, select the process that you want to pause, step through, or detach (detaching leaves process running, but won't hit the debugger anymore) and click the appropriate button in the Processes window's buttonbar.

-- Abel --
0
 
SanmarieAuthor Commented:
Thanks Abel. Very informative. Here's what I tried but I don't think I get everything you suggested as it's still not working for me or I'm not following your instructions properly.:

"allow edit and continue" is set to On and Break all processes when one process breaks is checked. I even unchecked this to see if it would work.
In the properties of the solution, I select "Multiple startup projects." I set the Host to "Start without debugging" and the client to just "Start" so that its assembly gets loaded.
Next, I run the solution so both the host and client gets started. I hit the break/pause button but I still get the following message:

Changes are not allowed while code is running or if the option break all processes when one process breaks is disabled. the option can be enabled in tools, options, debugging.

Edit a file not in the running project while not in break mode
(I did your instructions under this heading but still doesn't work)

Add a reference to a project while running
(I think that the book intends for me to add a reference to the client while the host project is running because the url of the host doesn't exist or won't be found unless the host is running and listening for requests)

Enabling Edit and Continue in ASP.NET
I couldn't find the "Web" option to "Enable edit and continue. Maybe I'm looking in the wrong place.

Thanks. Please help me out some more and show me where I'm going wrong.

San



0
 
abelCommented:
this:

> In the properties of the solution, I select "Multiple startup projects."
> I set the Host to "Start without debugging" and the client to just "Start" so that its assembly gets loaded.


will not work. The Host must be starting with debugging, otherwise, Edit and Continue will not work (that only works when Debugging is enabled). I didn't mean to use the option "Multiple startup projects". Just use one startup project. Using your instructions, I didn't manage to get it working either.

So: one startup project, configuration Debug (for all), really load the assembly (in your startup handler or something) but you do not need to do anything with it and hit Pause or a breakpoint. Then you can edit as much as you like.

------

> because the url of the host doesn't exist or won't be found unless the host is running and listening for requests
ok, so that is solved then, that's about something else then a library reference in VS.

> I couldn't find the "Web" option to "Enable edit and continue. Maybe I'm looking in the wrong place.

that's only inside ASP.NET. I don't believe you are using ASP.NET. It looks like you are using a WinForms project and a DLL, right?
0
 
SanmarieAuthor Commented:
Hi Abel,
I'll try your suggestions when I get home. Forgot to bring the source code with me to work.

I was just wondering why the host (the console application) needs to be started in debug mode because it is the client (the winforms application) that I want to modify. The host is just there to listen for incoming requests. I'll try it though.

>>>ok, so that is solved then, that's about something else then a library reference in VS.
I'm learing Windows Communication Foundation (WCF) so yes, this is not just adding a reference to a dll but adding a service reference (generating the proxy at the client). Visual studio gives the two options: Add a Reference (a dll) or Add a Service Reference.

>>that's only inside ASP.NET. I don't believe you are using ASP.NET. It looks like you are using a >>WinForms project and a DLL, right?
Well, I started out with a blank solution then I added a console application project (the host), a windows forms project (the client) and a class library project (the service type) so it didn't include an ASP.NET project in this case. However, there was another example in the book where I added an ASP.NET website as a service host with a windows forms project as the client. In this case I used the svcUtil command tool to generate the proxy for the client. Adding a Service Reference in Visual Studio does the same thing as the svcUtil tool.  VS studio just greys out this option for me because I'm not doing something wrong but I'll try your suggestions and get back to you.

Thanks

San



0
 
abelCommented:
> Visual studio gives the two options: Add a Reference (a dll) or Add a Service Reference.
well, you cannot do that while running an application, never, ever. Sorry for that. Or you have to add it dynamically, through code, which is quite a bit more work and a project on its own.

> I was just wondering why the host (the console application) needs to be started in debug mode
if you use multiple visual studios, this is not necessary. If you open the host outside visual studio, this is not necessary either (and you can still debug the client from within visual studio). Come to think of it, maybe it is not necessary, full stop. But while I tested, I needed the debug to true....
0
 
SanmarieAuthor Commented:
>>well, you cannot do that while running an application, never, ever. Sorry for that. Or you have to add >>it dynamically, through code, which is quite a bit more work and a project on its own.
Ok

>>>Come to think of it, maybe it is not necessary, full stop. But while I tested, I needed the debug to true.
Will try and let you know



0
 
SanmarieAuthor Commented:
Thanks Abel. It worked. I set breakpoints and that did it.
I set the host as the startup project then I started the client (Debug ->Start New Instance) with breakpoints in it. I was able to add code and save it while the host was running. I was hitting the pause key on the keyboard but VS kept telling me that changes are not allowed while code is running. I guess I don't know how to use the pause/break key.

I guess I need to reread the instructions in the book that says I should start the host then add a service reference to the client while the host is running. As you have explained, I cannot do this. I will email the author to clarify how to do this.

Thanks Abel, HalfAsleep, and Aleksei for all your help!

San
0
 
abelCommented:
> I was hitting the pause key on the keyboard but VS kept telling me that changes are
> not allowed while code is running. I guess I don't know how to use the pause/break key.

Interesting, never thought of that, but that's not what I meant and sorry for the confusion.

That Pause key on your keyboard is not meant for breaking your application. Incidentally, when you click the Pause button, you break the application where it's currently at, hence the Babylonian confusion. See screenshot for the correct location of that button.

ScreenShot246.png
0
 
SanmarieAuthor Commented:
Ok Abel. Thanks for the clarification. I thought the pause/break key was supposed to do the same thing as putting a breakpoint at a line. Well, that's how we learn. Thanks again for following up.

San
0
All Courses

From novice to tech pro — start learning today.