Start Visual Studio without StartWindow - automation

I need a programmatically start Visual Studio (devenv.exe) and open solution. I use EnvDte.
The problem is that EnvDTE.DTE.Solution.Open works, but StartWindow don't hide. If I click "Continue without code", I'll see the opened solution.
How can I programmatically close StartWindow?

You can customize it by setting the Startup option:
Click Tools -> Options -> Environment -> Startup
For On startup, open option select "Empty environment".

I don't find the way to close StartWindow programmatically.
The best one is to launch devenv.exe with /command argument:
devenv.exe /command "File.OpenProject {pathToSolution}"
https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-devenv-exe?view=vs-2019
https://learn.microsoft.com/en-us/visualstudio/ide/reference/visual-studio-commands?view=vs-2019

Related

How do I debug across application restarts in Visual Studio?

I'm building a Visual Basic application in Visual Studio 2010. Some of my options can only be applied on restarting the application.
I have not gotten a single crash when application is running normally. Nor does it crash when I apply settings, manually exit and restart. On the other hand, as soon as I try to do a automatic restart from the application, I get an exception on one out of 5-10 restarts.
I've tried to run the debugger, but as soon as the application restarts, the Visual Studio debugger is turned off and does not turn back on when the application launches again. Nor does it launch again with same configurations. It seems the debugger launched application configuration and the manually launched application configuration files are different.
Is there a way I can get around this? Keep the debugger on across restarts? Or should I undertake a different strategy?
Method 1: Attaching the debugger from within the application
If the application sometimes crashes at startup add a call to Debugger.Launch() in the application's Startup event. Doing so will cause Visual Studio to open a window where you can choose to attach its debugger.
You can check the Debugger.IsAttached property in order to determine whether a debugger is already attached or not.
Steps to subscribe to the Startup event:
Right-click your project in the Solution Explorer and press Properties.
Go to the Application tab.
Press View Application Events.
Select MyApplication (events) in the left combo box.
Select Startup in the right combo box.
Code:
Imports System.Diagnostics
...
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
If Debugger.IsAttached = False Then
Debugger.Launch()
End If
End Sub
Method 2: Letting Windows start the debugger, which in turn starts your application
An alternative solution is to add your application to the Image File Execution Options registry key, which allows you to specify a debugger which should launch the application for you.
NOTE: Adding your application to Image File Execution Options causes Windows to automatically launch the specified debugger instead of your application whenever you try to open it. Your application's path is passed as a command line argument and it is then up to the debugger to launch your application, attaching itself to it.
Malwarebytes have some info about Image File Execution Options on their blog: An introduction to Image File Execution Options.
Here's how you'd do it:
Open Regedit.
Navigate to the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options key.
Locate the key with the name of your application (if it exists), or create a new one in the format of yourApplicationName.exe.
Create a new String value (REG_SZ) and name it debugger.
Set the value of debugger to vsjitdebugger.exe.
Go ahead and start debugging!
For more information see: How to: Launch the Debugger Automatically - MSDN

Run interactive batch in Visual Studio post build events

I have a program written in vb.net. After I build, I want to launch an interactive batch file that executes a psexec command remotely. How can I do that?
this is my post build event:
call "$(ProjectDir)ExecOnGw.bat"
And this is my batch that if it runs in a normal command prompt, execution is ok.
c:\Sysinternal\psexec.exe \\gateway "C:\Remotepath\mybatch.bat" -u mydomain\myuser -p ******
pause
This batch calls another batch on a remote machine that does something, then if I want to exit, I have to press a "q" and "Enter". In a normal command prompt, it works fine. But in a Visual Studio post build event it goes down.
Help me!
I've done this before using the start command. I created a simple pause.bat file to demonstrate:
#echo off
pause Press Any Key
exit
If I put this in the post build event, I see a console that just closes.
call pause.bat
If I use this instead, I get a second console window that takes my input before closing.
start "My Process" /D c:\batch /WAIT pause.bat
Here is info about our technical development environment :
Microsoft Visual Studio Enterprise 2019
.NET Core 3.1
Just to add to #dsway good answer, I used Visual Studio 2019’s macros so that I could keep the directory path as relative:
start "My Process" /D "$(SolutionDir)Scripts" /WAIT blahblah.bat
Right-click on the Project in question
A context menu will show up
Select the Properties option
Select “Build Events”
Click on “Edit Post-build…”
Enter the aforementioned command that I posted above, and tailor it to your needs before pressing OK.

Debugging in OpenERP 7.0

How to do debug in OpenERP v7?
In previous versions of OpenERP, it was easy to debug. But in the latest version it's tough to debug.
To debug your OpenERP+python code in eclipse, start eclipse (helios/indigo only) in debug perspective and follow the given steps:
1: Stop your openERP running server by pressing "ctr+c".
2: In eclipse go to Menu "Run/Debug Configurations". In configuration window under "Python Run", create new debug configuration(Double click on 'Python Run').
3: After creating new debug configuration follow the given steps:
3.1: In "Main" tab under "Project", select the "server" project or folder (in which Openerp Server resides) from your workspace.
3.2: Write location of 'openerp-server' under "Main Module".
Ex: ${workspace_loc:server/openerp-server}.
3.3: In "Arguments" tab under "Program Arguments", click on button "Variables" and new window will appear.
3.4: Then create new "Variable" by clicking on "Edit Variables" button and new window will appear.
3.5: Press on "New" button and give your addons path as value.
Ex: --addons ../addons,../your_module_path
3.6: Press Ok in all the opened windows and then "Apply".
4: Now into "PyDev Package Explorer" view go to 6.1/server and right click on "openerp-server" file, Select 'Debug As --> Python Run'.
5: Now in "Console" you can see your server has been started.
6: Now open your .py file which you want to debug and set a break-point.
7: Now start your module's form from 'gtk' or 'web-client' and execution will stop when execution will reach to break-point.
8: Now enjoy by debugging your code by pressing "F5, F6, F7" and you can see value of your variables.
You can refer following link: Debug OpenERP Code from Eclipse
Go to Administrator(in right top corner) in that click on About OpenERP in that you will find a link Activate the Developer Mode.
or
you can add a parameterdebug in of URL like
http://localhost:8069/?debug
both the way will let you open the developer mode.
You can also use the Odoo Debug pro chrome extension to toggle the developer mode using the keyboard shortcuts.
To debug openERP 7 from eclipse just Stop openERP server and rename the main file named openerp-server.py.From "Run/Debug Configurations" make a new configuration selecting Project and main module such as ${workspace_loc:openerp7/src/openerp-server.py} then press Apply.After that /openerp7/src/openerp-server.py 'Debug As --> Python Run' using new configuration.Server is running where pydev debugger is also started.Now run 'gtk' or 'web-client'.Then select the python file of that module where want to debug and give breakpoints.That's all.
Debugging is quite simple in interface.
For Programmers
By Default when you login to openerp, your url will look something like this
http://localhost:7373/?db=Test_July_25#menu_id=107&action=97
Edit the url and add debug=&
localhost:7373/?debug=&db=Test_July_25#menu_id=107&action=97
For Functional Users
Navigate mouse to top right corner and select About OpenERP
Now Activate Debug Mode
You Should be done now with interface debugging.
For Code Debugging (along with arya's method these images may help you)
You can use browse button to select the project and the openerp server file
Finally place breakpoints in your code where ever necessary
Navigate through
administrator(top Right)>>about OpenERP
Dialog Open Click on Activate Developer mode
Their is more complexity and less control by adding more fancy tools try and go low level and use python pdb and if you are debug geek then use winpdb with pdb which gives extreme contorl over your code navigation.
And for simple value abd flow use print or pprint module from python.
Bests.
Start debug mode on browser ??
In URL you can type ?debug after web
OR
go to About OpenERP select Activate Developer Mode
If You want to debug from eclipse then
go to PyDev Package Explorer --> openerp(odoo) --> Right click on openerp-server file
Select Debug as --> Python Run
It will ask for change current perspective from PyDev to Debug click "Yes" and its Done
Activate the Debug mode and use some print statements to debug the variable values

How to open multiple .sql files in only one ssms instance

I'm DBA with a new server box running Windows Server 2008 Enterprise SP1 with SQL Server 2008 and SQL Server Management Studio.
In my previous box when working in Visual Studio with database solution with lot of .sql files I used to double-click on the .sql files and they were opened in the same SSMS instance (if any already opened). However (even when having exactly the same installation in the new box) I'm now getting a new SSMS instance when double clicking in each sql file. Its really painful one .sql - one SSMS instance so I started my research about that.
What I've tried till now:
1) Right click on the .sql file > "Open With" option > "Add" option > "Program Name: C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" and "Friendly Name: SQL" > "Ok" > "Set as Default". Does NOT work. Still having one sql - one ssms instance.
2) Perfomed Run > regedit > and modify the value data of HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command and replace /dde with "%1". DOES NOT WORK
3) Right click on the .sql file > "Open With" option > "Add" option > "Programe Name: explorer.exe" and "Friendly Name: Explorer" > "Ok" > "Set as default". Does NOT work. When double-clicking on the .sql files Notepad comes with scripts content.
4) Some pages like this
http://social.msdn.microsoft.com/Forums/en/sqltools/thread/ac2f39c5-66e5-495c-b7a6-47e743853baf
asks to change file association but when opening Windows Explorer > Tools > Folder Options ... I found there is no "File Type" tab. How annoying!
Can someone help me on that? My patient it's really running out.
Thanks in advance
After spending most of my working day looking for the solution I finally found it. Thanks God, I was almost running out with this issue. Hope it helps somebody else!!!.
Update: linked domain expired, so here's what it said:
Considering how integrated Microsoft tools usually are the result is
frustrating when you tell Visual Studio to open SQL files using Sql
Server Management Studio (SSMS). I really don't like using Visual
Studio to edit T-SQL files but in the past, before I discovered this
tip, each SQL file I opened would open in a new instance of SSMS. Try
it:
Open a solution which contains SQL files
Right-click any SQL file and select “Open With…”
Click “Add”
Browse to "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" or if you're
running x64 Windows "C:\Program Files (x86)\Microsoft SQL
Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe", then click “OK”
Click “Set as Default” and then “OK”
Now open multiple SQL files. Each time you'll get a different instance
of SSMS opened. What a pain!
NOTE: This entire article applies to SQL 2005, just replace SSMS with
SQLWB.
How do you resolve this? Repeat steps 1-3 above, but at step #4 enter
the following values:
Program Name: “explorer.exe”
Friendly Name: “Windows Explorer”
Repeat step #5 (set as default) above and then click OK. Now, open
additional files. They should all open in the same instance of SSMS.
It would seem that Visual Studio issues a command to SSMS.exe which
includes the path of the file selected in the solution explorer. It is
up to SSMS to check for a new instance, which it doesn't. But when you
pass the file name to explorer it gets opened up in the same instance.
QUIRK WARNING!
If SSMS is not already open, the first file you attempt to open (not
first time ever, but every time you open an SQL file from Visual
Studio and SSMS isn't open yet) SSMS will open, but your file will
not. Click the file a 2nd time and it will open the file this time.
Don't ask me to explain it it just is (and I have no idea why).
Conclusion
The result when you tell Visual Studio that SSMS is the default editor
makes sense, but I don't get why it would be different when you tell
explorer to open it. Maybe if I were a Windows developer instead of a
web developer I would know the answer. But either way, now you know.
Enjoy.
I have this problem before, I found there is a simple solution -> just check if your SSMS is under "Run this program as an administrator" option (right click on the shortcut icon -> property -> Compability -> Privilege level). If yes, untick the option and try double click the sql file.
Hope this helps.
Similar issues have been reported multiple times, but they aren't addressing the issue (removed links because Microsoft erased Connect without much thought):
~connect.microsoft.com/VisualStudio/feedback/details/105575/multiple-instances-of-sqlwb-exe-when-management-studio-set-as-default-editor~
http://web.archive.org/web/20130727043341/http://connect.microsoft.com/SQLServer/feedback/details/622181/multiple-ssms-open-for-seperate-sql-files
~connect.microsoft.com/SQLServer/feedback/details/680761/a-new-instance-of-ssms-is-opened-when-trying-to-open-a-tsql-file-even-when-an-instance-is-running~
Did you install Visual Studio (or any Visual Studio components) after installing SQL Server?
My guess is that the Connect items will not be fixed - SQL will blame Visual Studio, Visual Studio will blame SQL, and the items will remain open...
So here is what I suggest: run a repair of SQL Server from Programs and Features and then re-apply the latest service pack of SQL Server 2008 (SP2).
Also the "File Types" interface was moved from the Tools / Folder Options interface to the Control Panel. Go into Control Panel > Default Programs > "Associate a file type or protocol with a program." However it doesn't seem to have the options here to add command-line options like "%1" or /dde.
Try adding these reg keys as well, but make sure you put the /dde back in:
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec]
#="Open(\"%1\")"
For the record, here is my entire export for that section:
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open]
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command]
#="\"C:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\VSShell\\Common7\\IDE\\ssms.exe\" /dde"
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec]
#="Open(\"%1\")"
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec\application]
#="sqlwb.9.0"
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec\topic]
#="system"
Go to Tools >> Folder Options >> File Types and apply below settings. It worked for me finally!!! (after half a day search on google).
Click New/Edit (on this window "Confirm open after download" should be check and "Always show extension" should be unchecked)
In next window, make below entries
- Action: Open
- Application used to perform action : Your ssms.exe path like "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"
- Check "Use DDE" check box
- DDE Message : Open("%1")
- Applicajtion sqlwb.9.0
- DDE Application Not Running: Keep it empty
- Topic : system
Regards,
Sandeep Gaadhe
I am using SQL Server Management Studio 2012 Express and I have made this to work by pointing "Program" to "explorer.exe"
This is how my register is set up: "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\ssms.exe" /dde
at
HKEY_CLASSES_ROOT\ssms.sql.11.0\Shell\Open\Command
I've 2005 & 2008 SSMS installed so I defaulted to the 2005 instance. If I have 2008 ssms open when opening a .sql file from windows explorer it will now open in the existing 2008 ssms (and not try to open a new instance!)
From Windows Explorer, one can drag-and-drop selected files (single or multiple) into an SSMS window.
One thing to check is if you have multiple versions of SSMS. If you happen to be working in an older version, double clicking on a file will open the new SSM version. Or whatever the default version is for sql files.
A quick note for users who want to have SSMS always open with Administrator privileges.
Find SSMS in your start menu. Right-click>More>Open File Location.
Once you see the shortcut to Microsoft SQL Server Management Studio * in Windows Explorer, Right-click>Open File Location.
Then Right-click on Ssms.exe>Troubleshoot compatibility.
Then click Troubleshoot program.
Put a tick by The program requires additional permissions then hit Next.
Now it forces you to press Test the program....
Then press Next and then Yes, save these settings for this program.
Arvo Bowen Jan 30 '20 at 15:27
This work perfectly.
I know this is quite an old post and there are loads of different answers with possible solutions. But here's one I think is new (at least to SO).
I suddenly starting getting this behaviour (i.e. each new file would open in a new session) and couldn't figure out why. Turns out it was because in my SSMS session I had an open dialogue which had dropped into the background.
A soon as I closed the dialogue, new files started opening in my original session /facepalm
Maybe everyone knows this already but just in case it saves anyone 20 mins!
My issue with multiple SSMS instances version 19 was fixed by changing HKEY_CLASSES_ROOT.sql Default key to

Debug.WriteLine not working

In the past, perhaps versions of Visual Studio prior to the 2008 that I am using now, I would do something like this in my VB.NET code:
System.Diagnostics.Debug.WriteLine("Message")
..and the output would go to the output window.
Now it doesn't. Something must first apparently be enabled.
If this involves "attaching a debugger", please explain how to do it. It seems to me that it should just work without too much of a fuss.
Here's a video explaining the issue in real time and showing you all my settings:
http://screencast.com/t/YQnPb0mJcs
I'm using Visual Studio 2008.
Check to see if the "Redirect all Output Window text to the Immediate Window" is checked under Tools -> Options -> Debugging -> General.
Alternatively, you can use the Console.WriteLine() function as well.
Right-click in the output window, and ensure "Program output" is checked.
All good suggestions. I noticed that I don't see this tip mentioned, so I'll say it: In your app.config file, make sure you don't have a <clear/> element in your trace listeners.
You will effectively be clearing the list of trace listeners, including the default trace listener used for Debug statements.
Here's what this would look like in your app.config file:
<system.diagnostics>
<trace>
<listeners>
<!-- This next line is the troublemaker. It looks so innocent -->
<clear/>
</listeners>
</trace>
</system.diagnostics>
If you want to have a placeholder for trace listeners in your app.config file, you should instead use something like this:
<system.diagnostics>
<trace>
<listeners>
</listeners>
</trace>
</system.diagnostics>
Do you definitely have the DEBUG constant defined? Check under project properties -> Compile -> Advanced Compile Options (there's a checkbox for the DEBUG constant. If it isn't checked, your Debug.XXX statements will not be executed).
It should go to the output window if your app is compiled with the Debug configuration rather than the Release configuration. But instead of Debug.WriteLine(), try using Trace.WriteLine() (optionally with a ConsoleTraceListener attached).
Some extra ideas to try or check:
Put a breakpoint before Debug.WriteLine and see what's in System.Diagnostics.Trace.Listeners collection. You should see DefaultTraceListener. If you don't see anything, then no one is listening and that's problem.
Is it possible that the trace listeners being cleared/modified somewhere such as in config file or in the code?
Have you installed any package or add-in to Visual Studio? or using a third-party library?
Can you see debug messages outside of VS? There is a SysInternals application called DebugView that monitors and shows debug output in your system. Run that tool and then run your application. You should see your debug message in DebugView. At least you will know that your application is outputting debug messages but VS does not seem to be listening.
Have you gone through the contents of the output window to see if there is any exception or error being reported. Your debug output is not there but there might be somethings in there that can provide some clues.
Check your Immediate Window. You might have all the output redirected to it.
For me this was the fact that Debug.WriteLine shows in the Immediate window, not the Output. My installation of Visual Studio 2013 by default doesn't even show an option to open the Immediate window, so you have to do the following:
Select Tools → Customize
Commands Tab
View | Other Windows menu bar dropdown
Add Command...
The Immediate option is in the Debug section.
Once you have Ok'd that, you can go to menu View → Other Windows and select the Immediate Window and hey presto all of the debug output can be seen.
Unfortunately for me it also showed about 50 errors that I wasn't aware of in my project... maybe I'll just turn it off again :-)
It happens. I have the similar symptom when I am developing ASP.NET MVC applications on Visual Studio 2010 web developer Express Edition. The execution doesn't break at the breakpoint. There is no output when it executes System.Diagnostic.Debug.Writeline (even though it runs with debug start), and there is nothing wrong with web.config.
My workaround is:
- Goto project properties--> web
- In the Debugger section, check the the ASP.NET option
Hope this helps someone who comes across this thread.
I was having the same problem for an ASP.NET application, and I found out that my Web.Config had the following line:
<system.web>
<trace enabled="false"/>
</system.web>
Just changing it to true, and I started seeing the Debug.WriteLine in Output window.
I had a similar issue with Visual Studio 2013 and MS unit testing. Right clicking on a unit test method and selecting Run Tests any Debug.WriteLine calls would not show up in either the immediate window or the debug output window. Even though the library I was testing and the unit test project itself both had DEBUG conditional checked in the build section of there project properties.
In order for the Debug.WriteLine statements to output anything I needed to run the unit tests by right clicking and selecting Debug Tests. Only then did I get the debug output being written to the debug output window.
I had the same problem in Visual Studio Express 2010. I fresh installed on a debug machine and none of the suggestions worked. I ended up using NLog and logging to a text file as a workaround.
Make sure you press F5 to Start Debugging mode (not Ctr+F5).
F5 Starting Debugging
CTRL+F5 Starting Without Debugging