Visual studio .SLN executing Exe file / .VBS script - visual-studio-2010

How to launch .Exe file or .VBS script when visual studio solution(.sln) is opened ?

Associate a .SLN file with your own executable instead of devenv. In your executable, if the solution being opened matches then delete the necessary files. Then execute the devenv and pass the solution full path and name as a parameter.

Related

How to get folder of the cmd script source, or to set it's source folder as current?

If I run a .cmd script (powershell) in windows from a different folder, (which may be relative, and the .cmd script might be relative to this) I don't know what folder the .cmd script is running in. This happens in the post build step of visual studio. The cmd script might perform operations on the current folder, which might not be it's source folder, thus an error. Its own source folder might be different than the folder it's being called from. I need a variable that gives it's own folder, not the 'current' folder, or perhaps just to set it's own source folder as current.
The post-build step in visual-studio can run a .cmd script in a relative folder, and the cmd script runs in the visual studio's project folder.

Visual studio: How to open a specific solution directly from command line?

I want to open a specific solution (.sln) in visual studio directly from the command line.
Using the command, I tried
devenv "full-path-to-sln-file.sln"
but it didn't work.
How do I do this?
You can just use explorer.exe !!
In your command line type in:
explorer mysolution.sln
Use the full path to the devenv.exe executable and the full path to the sln solution file, both wrapped in quotes and with a space in between. If your solution file is in a network path, make sure that it does not require authentication before accessing the destination folder.
C:\Users\YourWindowsUser>"D:\Visual Studio\Common7\IDE\devenv.exe" "\\networkDirectory\profiles\Desktop\VisualStudioSolutions\Project999.sln"
I wrote an open source application called OpenVSSolution to do exactly this.
Essentially:
Put this helper exe somewhere in your PATH
The exe scans the current directory for a .sln file
The exe opens devenv passing in the sln file
The explanation is on here:
https://davemateer.com/coding/2018/11/14/Open-visual-studio-from-command-line.html
I find this incredibly useful and is how I open all solutions.
You can open a solution file with Visual Studio directly if you are within a folder that contains the solution file, looking for it recursively (Powershell 7.0) by doing the following:
Open powershell, type
echo $profile
Open up the location of your profile, save the below into it:
function vs
{
Get-ChildItem *.sln -Recurse | Invoke-Item
}
Then just type vs into a folder and it will go through the sub directories looking for the solution file and open one if found
Try WhatsNew. From the readme:
Why fish around for Visual Studio solution files using Windows Explorer when you can find and launch them from your terminal window with just three little letters? Run sln (an alias for Open-Solution) to recursively search your current working directory for a solution file and launch it, if one is found.
for macOs I just use:
open projectname.csproj
it will open it in visual studio 2019 for me

Possible to Auto Open file in Visual Studio

I currently use the following cleartool command using Visual Studios External tool interface:
Command: \installationpath\cleartool.exe
Arguments: annotate -nheader $(ItemPath)
Initial directory: $(ItemDir)
I do use the output window. Which will let that command print out the location of the .ann file it produces. I'm wondering if there is a way for Visual studio to auto open that produced file?
In this case its not a huge hardship to copy the location and open the file. I'm just always looking for ways to make things easier.
Using just one external tool, you wouldn't be able to execute cleartool, and to open a file (generated from the cleartool command).
You can open a file from a Visual Studio External Tool as explained here, but that wouldn't execute cleartool.
So I would recommend executing a script (.bat, .cmd, .vbs) in order to:
do the cleartool command you want
open the generated file.
You would pass to this script no only $(ItemPath), but also, depending on where it is generated, $(ItemDir), or $(ProjectDir), or $(SolutionDir), or $(TargetDir).

bat script only runs first line?

When I copy/paste the lines below into a cmd window it executes without a problem.
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
msbuild proj\projsln /p:Configuration=Debug
proj\proj\bin\Debug\proj.exe my args
However when I save it as DoStuff.bat I get the message below (which is the text from executing vcvars32.bat), then nothing else. It does not build my project and obviously doesn't run the newly built executable.
Why doesn't it and how do I have it run all three commands?
>"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
Use CALL to call another batch file.
Well, there has to be a reason it isn't continuing. Is it that the command is waiting for some input? Thats all that I can think of. Try re-directing the output of the batch file to a log and see what is going on.
Alternatively, split the batch file into separate batch files and put a CALL before each call to the batch file.

Bat file - not finding .exe

If I create an .exe file with Visual Studio 2010 (in the bin/Debug folder) is it possible to use a bat file to start this program?
I tried the below in my bat file:
start "c:\Services\ServicesChecker\ServicesChecker\bin\Debug" ServicesChecker.exe
however when I run it, it says Windows cannot find ServicesChecker.exe even though if I browse to the location I can see it?
In your command, the "c:\Services\..." is the title given to the window, and is not used to find the executable.
Try:
start c:\Services\ServicesChecker\ServicesChecker\bin\Debug\ServicesChecker.exe
Its because there is no option in start by which you can specify the path.
Use
start "c:\Services\ServicesChecker\ServicesChecker\bin\Debug\ServicesChecker.exe"
this should work.
Try just using the file path rather than start, and you need to include the filename in the same quoted path, like this:
"c:\Services\ServicesChecker\ServicesChecker\bin\Debug\ServicesChecker.exe"

Resources