Quickly enter command-line parameters for Visual Studio debugging? - c++

I want to change my command-line arguments and then debug my executable.
With the default Visual Studio UI, this takes me several tortuous mouse and keyboard actions:
Project ... right click ... Configuration Properties ... Debugging ... Command Arguments ... type args ... ENTER ... F5
Is there a way to make this common action as easy as other common operations, for example, searching all files for a pattern which goes:
CNTL+SHIFT+F ... type search pattern ... ENTER
For example, is there an way to create a custom edit box to allow quick access to the debug command-line arguments? Or a way to have a key-binding pop up a simple "debug dialog" where the args can be entered and debugging started directly? e.g.
ALT+F5 ... type args ... ENTER
I am using C++ and Visual Studio 2010 Express. Thanks!

The extension CLIArgsMadeEasy 2010/2012 is a great little thing that puts the project's debug session's command line arguments right in a little text box on the visual studio toolbar, IMO, its alot easier and less tedious than using macros.
The Link
http://visualstudiogallery.msdn.microsoft.com/8159cd7d-2c81-47f3-9794-a347ec1fba09?SRC=VSIDE
You can just type CLIArgsMadeEasy in your search box in the extensions manager which will find it fairly quickly in the gallery, thats how I installed it, if you need to know. Hope this helps!

Macro below should help. Open "Tools->Macros->Macro Explorer", then create new module, edit it, and copy-paste code below. Required command is SetCommandArgsProperty. UI is not nice, but it works (VS 2005, I hope this will also work in VS 2010). Then add any shortcut you like to run this macro.
Here are some details:
Find startup project
Select it active configuration and find property with name "CommandArguments"
Create edit box with the current value in it
Update property if OK is selected
Sub SetCommandArgsProperty()
Dim newVal As Object
newVal = InputValue(GetCommandArgsPropertyValue())
If TypeOf newVal Is String Then
SetCommandArgsProperty(newVal)
End If
End Sub
Function InputValue(ByVal defaultText As String)
Dim frm As New System.Windows.Forms.Form
Dim btn As New System.Windows.Forms.Button
Dim edit As New System.Windows.Forms.TextBox
edit.Text = defaultText
edit.Width = 100
btn.Text = "OK"
btn.DialogResult = System.Windows.Forms.DialogResult.OK
frm.Text = "Input command line properties"
frm.Controls.Add(btn)
btn.Dock = System.Windows.Forms.DockStyle.Bottom
frm.Controls.Add(edit)
edit.Dock = System.Windows.Forms.DockStyle.Top
frm.Height = 80
frm.Width = 300
If frm.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Return edit.Text
End If
Return System.DBNull.Value
End Function
Function GetCommandArgsProperty() As EnvDTE.Property
Dim solution As Solution
Dim project As Project
Dim sb As SolutionBuild
Dim str As String
Dim cm As ConfigurationManager
Dim config As Configuration
Dim properties As Properties
Dim prop As EnvDTE.Property
solution = DTE.Solution
sb = solution.SolutionBuild
For Each str In sb.StartupProjects
project = solution.Item(str)
cm = project.ConfigurationManager
config = cm.ActiveConfiguration
properties = config.Properties
For Each prop In properties
If prop.Name = "CommandArguments" Then
Return prop
End If
Next
Next
End Function
Function GetCommandArgsPropertyValue()
Return GetCommandArgsProperty().Value
End Function
Sub SetCommandArgsProperty(ByVal value As String)
GetCommandArgsProperty().Value = value
End Sub

At least in Visual Studio 2012, you can use Alt+F7 shortcut to directly access project properties.
Furthermore, the opened Property Pages normally remembers the last opened item, i.e. Configuration Properties -> Debugging.

Related

How do I use Roslyn with a Website project?

In my Visual Studio Package I get the VisualStudioWorkspace as described by Josh Varty
https://joshvarty.com/2014/09/12/learn-roslyn-now-part-6-working-with-workspaces/
Using the EnvDTE.Project object, I look for a matching Roslyn project in VisualStudioWorkspace.Projects by comparing the properties CodeAnalysis.Project.FilePath and EnvDTE.Project.FileName.
If I find a match, then I know that the project supports Roslyn and that I can find documents in the CodeAnalysis.Project.Documents collection. This has so far worked fine for C# and VB projects.
If I do not find a match, then it might be a C++ project, which does not support Roslyn.
However, I have now found that WebSite projects behave quite differently.
I have created a new WebSite project in Visual Studio 2019. Althouth the solution only contains one project, the VisualStudioWorkspace contains two CodeAnalysis.Project objects, as follows:
?VSWorkspace.CurrentSolution.Projects(0)
1_Default.aspx
AdditionalDocumentIds: Count = 0
AdditionalDocuments: {System.Linq.Enumerable.WhereSelectEnumerableIterator(Of Microsoft.CodeAnalysis.DocumentId, Microsoft.CodeAnalysis.TextDocument)}
AllProjectReferences: Length = 1
AnalyzerConfigDocuments: {System.Linq.Enumerable.WhereSelectEnumerableIterator(Of System.Collections.Generic.KeyValuePair(Of Microsoft.CodeAnalysis.DocumentId, Microsoft.CodeAnalysis.AnalyzerConfigDocumentState), Microsoft.CodeAnalysis.AnalyzerConfigDocument)}
AnalyzerOptions: {Microsoft.CodeAnalysis.Diagnostics.AnalyzerOptions}
AnalyzerReferences: Length = 0
AssemblyName: "1_Default"
CompilationOptions: {Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions}
DefaultNamespace: ""
DocumentIds: Count = 2
Documents: {System.Linq.Enumerable.WhereSelectEnumerableIterator(Of Microsoft.CodeAnalysis.DocumentId, Microsoft.CodeAnalysis.Document)}
FilePath: Nothing
HasDocuments: True
Id: (ProjectId, #ca6b1f58-967a-4c31-a874-71d7720dd972 - 1_Default.aspx)
IsSubmission: False
Language: "C#"
LanguageServices: {Microsoft.CodeAnalysis.Host.Mef.MefLanguageServices}
MetadataReferences: Length = 56
Name: "1_Default.aspx"
OutputFilePath: Nothing
OutputRefFilePath: Nothing
ParseOptions: {Microsoft.CodeAnalysis.CSharp.CSharpParseOptions}
ProjectReferences: {System.Linq.Enumerable.WhereEnumerableIterator(Of Microsoft.CodeAnalysis.ProjectReference)}
Solution: {Microsoft.CodeAnalysis.Solution}
SupportsCompilation: True
Version: {2019-10-13T06:46:42.2691386Z-10141-0}
?VSWorkspace.CurrentSolution.Projects(1)
2_App_Code
AdditionalDocumentIds: Count = 0
AdditionalDocuments: {System.Linq.Enumerable.WhereSelectEnumerableIterator(Of Microsoft.CodeAnalysis.DocumentId, Microsoft.CodeAnalysis.TextDocument)}
AllProjectReferences: Length = 0
AnalyzerConfigDocuments: {System.Linq.Enumerable.WhereSelectEnumerableIterator(Of System.Collections.Generic.KeyValuePair(Of Microsoft.CodeAnalysis.DocumentId, Microsoft.CodeAnalysis.AnalyzerConfigDocumentState), Microsoft.CodeAnalysis.AnalyzerConfigDocument)}
AnalyzerOptions: {Microsoft.CodeAnalysis.Diagnostics.AnalyzerOptions}
AnalyzerReferences: Length = 0
AssemblyName: "App_Code.yy7qumxk"
CompilationOptions: {Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions}
DefaultNamespace: ""
DocumentIds: Count = 5
Documents: {System.Linq.Enumerable.WhereSelectEnumerableIterator(Of Microsoft.CodeAnalysis.DocumentId, Microsoft.CodeAnalysis.Document)}
FilePath: Nothing
HasDocuments: True
Id: (ProjectId, #12ab68ac-7b29-4252-87c2-67dc2f3d0696 - 2_App_Code)
IsSubmission: False
Language: "C#"
LanguageServices: {Microsoft.CodeAnalysis.Host.Mef.MefLanguageServices}
MetadataReferences: Length = 53
Name: "2_App_Code"
OutputFilePath: Nothing
OutputRefFilePath: Nothing
ParseOptions: {Microsoft.CodeAnalysis.CSharp.CSharpParseOptions}
ProjectReferences: {System.Linq.Enumerable.WhereEnumerableIterator(Of Microsoft.CodeAnalysis.ProjectReference)}
Solution: {Microsoft.CodeAnalysis.Solution}
SupportsCompilation: True
Version: {2019-10-13T06:46:41.6118955Z-10139-2}
First of all, the FilePath property in both projects is null, so I was not able to identify the project by its filename.
The two projects contain a total of seven documents, which are:
"C:\DotNetTestPrograms\2019\CS\WebSite1\Default.aspx.cs"
"C:\DotNetTestPrograms\2019\CS\WebSite1\Default.aspx"
"C:\DotNetTestPrograms\2019\CS\WebSite1\App_Code\BundleConfig.cs"
"C:\DotNetTestPrograms\2019\CS\WebSite1\App_Code\IdentityModels.cs"
"C:\DotNetTestPrograms\2019\CS\WebSite1\App_Code\RouteConfig.cs"
"C:\DotNetTestPrograms\2019\CS\WebSite1\App_Code\Startup.Auth.cs"
"C:\DotNetTestPrograms\2019\CS\WebSite1\App_Code\Startup.cs"
This is not a complete list of documents in the project. The project contains seven additional-code behind files:
Account\Login.apsx.cs
Account\Manage.apsx.cs
Account\OpenAuthProviders.ascx.cs
Account\Register.apsx.cs
Account\RegisterExternalLogin.apsx.cs
Site.master.cs
ViewSwitcher.ascx.cs
My question is, can I work with Roslyn in a WebSite project?
Clearly, there is not a one-to-one relationship between EnvDTE and CodeAnalysis projects. I guess that I could work around that.
But what about the missing files? Are there not Roslyn documents for the seven additional code-behind files?
I finally looked at this problem again and I have found the following solution.
This method only works if the document is open in Visual Studio. Therefore I start of with
projectItem.Open ( EnvDTE.Constants.vsViewKindTextView ) ;
(I already have the project item in my function, so this is easy.)
Then, with the full path to the file (FullPath) and the VisualStudioWorkspace (VSWorkspace), I can get the Roslyn Document with
var docid = VSWorkspace.CurrentSolution.GetDocumentIdsWithFilePath(FullPath).FirstOrDefault() ;
if ( docid != null )
{
var RoslynDoc = VSWorkspace.CurrentSolution.GetDocument ( docid ) ;
}
If the document was not already open, it would probably be good practice to close it again, when you are finished. You can determine whether the document was previously open with
var wasOpen = projectItem.IsOpen ( EnvDTE.Constants.vsViewKindTextView ) ;
By the way, opening the document like this does not make the window visible in Visual Studio (which in my application is fine). If you want to make it visible you can open it like this:
var wnd = projectItem.Open ( EnvDTE.Constants.vsViewKindTextView ) ;
wnd.Visible = true ;

OpenFileDialog component in Visual Studio 2017

I'm working on a VB project in Visual Studio 2017. It's a Blank App (Universal Windows) project. When trying to work with this type of app, it doesn't seem to have an OpenFileDialog like the Windows Forms App (.NET Framework) has. Is there a way to do one of two things:
Create a Windows Forms App that has the same look and feel as the Blank App (Universal Windows)
Add the OpenFileDialog option to the Blank App (Universal Windows)
The following code is a VB version of the MS example at https://learn.microsoft.com/en-us/uwp/api/Windows.Storage.Pickers.FileOpenPicker.
Imports Windows.Storage
Imports Windows.Storage.Pickers
Public NotInheritable Class MainPage
Inherits Page
Private Async Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim openPicker As New FileOpenPicker()
openPicker.ViewMode = PickerViewMode.Thumbnail
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary
openPicker.FileTypeFilter.Add(".jpg")
openPicker.FileTypeFilter.Add(".jpeg")
openPicker.FileTypeFilter.Add(".png")
Dim file As StorageFile = Await openPicker.PickSingleFileAsync()
If (file IsNot Nothing) Then
Debug.WriteLine($"Picked File: {file.Name}")
Else
Debug.WriteLine("Operation Cancelled.")
End If
End Sub
End Class
What I ended up doing to get the same(ish) look was to just play around with some of the properties of the form and the buttons. This gave me the look that I was after. It wasn't exact, but I'll take it.
As for OpenFileDialog, I ended up using the following:
Dim myStream As IO.Stream = Nothing
Dim openFileDialog1 As New OpenFileDialog()
' Open file dialog parameters
openFileDialog1.InitialDirectory = "c:\" ' Default open location
openFileDialog1.Filter = "Executable Files (*.exe)|*.exe|All Files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
myStream = openFileDialog1.OpenFile()
If (myStream IsNot Nothing) Then
' Insert code to read the stream here.
Textbox1.Text = openFileDialog1.FileName
' Even though we're reading the entire path to the file, the file is going to be ignored and only the path will be saved.
' Mostly due to me lacking the ability to figure out how to open just the directory instead of a file. Resolution threadbelow.
' http://www.vbforums.com/showthread.php?570294-RESOLVED-textbox-openfiledialog-folder
' Setting the public variable so it can be used later
Dim exepath As String
exepath = IO.Path.GetDirectoryName(Me.txtExeLocation.Text)
End If
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
Finally
' Check this again, since we need to make sure we didn't throw an exception on open.
If (myStream IsNot Nothing) Then
myStream.Close()
End If
End Try
End If

Does webstorm have some shortcut for console.log or console.info?

Just tired of typing console.log again and again, and do not find a way like Sysout + Control + Space in Eclipse will create System.out.println().
There's a predefined Postfix template that allows you to type .log after a JavaScript expression or string and hit Tab to transform it to console.log().
You can also create a Live template (see Preferences | Editor | Live templates) that would expand into a code snippet once you type the selected abbreviation and hit Tab.
Update: there's now also a plugin that allows you to add console.log with a shortcut: https://plugins.jetbrains.com/plugin/10986-console-log
Yes it does,
<anything>.log and press Tab key. This will result in console.log(<anything>);
ie,
<anything>.log + Tab => console.log(<anything>);
eg1: variable
let my_var = 'Hello, World!';
my_var.log + Tab => console.log(my_var);
eg2: string
'hello'.log + Tab => console.log('hello');
eg3: string and variable
'hello', my_var.log + Tab => console.log('hello', my_var);
[UPDATE 2020]
Typing log + Enter autocompletes to console.log()
I made my own template that seems to work.
It may be useful for somebody.
Abbreviation: ll
Template text:
console.log('$NAME$ ', $VALUE$);
$END$
Variables: (just select the given field values by clicking drop down box)
NAME - jsDefineParameter()
VALUE - jsSuggestVariableName
I'm including what I find to be the most efficient, which I added via live templates -> javascript -> applicable to "Everything". Hopefully someone finds it useful.
console.log('L$LINE$ $MYSTRING$ ===', $MYVAR$);$END$
What it does:
When I type cl and press tab, it creates the log and the first thing you type fills both MYSTRING and MYVAR variables. If you tab again, it selects MYVAR where you can rewrite/delete as desired. The third time you hit tab will take you to the end of the line at $END.
This snippet also prints the line number like L123 but you can easily remove that if it isn't helpful because obviously most browsers show line number anyway.
You also have to set the variables' behaviour as seen in the image below:
Edit variables setup
use Macros!
https://www.jetbrains.com/help/webstorm/using-macros-in-the-editor.html
I recorded a macro that takes the name my cursor is on and create
console.log("#### name = ", name);
on the next line.
and assigned a keyboard shortcut to it :)
super easy, and couldn't get Live Template to get the same result with 1 action.
to create a new macro: Edit -> Macros -> Start Macro Recording. then record your next moves and create the desired result.
this is mine:
This is my solution, it somewhat mimics a turbo-console approach and gives you certain freedoms to build on it.
Step 1: Go to Editor > General > Postfix Completion;
Step 2: Click on JavaScript, click the + button, select JavaScript and TypeScript;
Step 3: In the Key input, type a alias for your command, I choose 'cl' for mine;
Step 4: In the 'Minimum language level' select your desired preference, I choose ECMAScript 6+;
Step 5: In the bellow text area, add your logic, for me it is console.log('$EXPR$', $EXPR$, '$END$');
Step 6: Customize however you like.
So what does all of this do?
Lets consider the following:
const willNeedToBeLogged = 'some value you want to check';
All you need to do for a console long is type
willNeedToBeLogged.cl + press (Tab, Enter or Spance)
And you will get this
console.log('willNeedToBeLogged', willNeedToBeLogged, '');
With your cursor being on the $END$ variable, where you could write, a line, or anything you like.
Have fun!
I made a custom template. This can help you.
Abbreviation: clog
Template code:
console.log("\n\n--------------------------------");
console.log($END$);
console.log("--------------------------------\n\n");
Simplest live template text:
console.log($END$);
Maybe it is a recent addition but you can write log and hit tab and console.log() will appear with the caret in between the braces.
The answer from Ekaterina Prigara (https://stackoverflow.com/a/32975087/5653914) was very useful to me but if you want to log a string like "Test" this method is quicker.
Try a logit plugin. It provides the next logging pattern by default:
const data = 'data';
console.log('-> data', data);
You can configure it.
Try Dot Log (vscode extension), It can automatically transfer aaa.log to console.log('aaa', aaa )

Change header with macro in Word Template on SharePoint

I'm working on a Word template that the user can access from Sharepoint.
In this template I have made a custom ribbon with custom ui editor.
I want the users to be able to choose a header and a footer.
For this I have already made 2 different headers (1 with fields and 1 without) and saved them in the template.
So when I want to insert a header I can select them like this: Insert --> Header --> scroll all the way down to 'Template' and select one of them. This works perfect. I've recorded a Macro of this process so I am able to use this on my custom ribbon.
the macro looks like this:
Sub Header()
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Application.Templates( _
"http://spf.mysite.be/Shared%20Documents/Template.dotm"). _
BuildingBlockEntries("Header").Insert Where:=Selection.Range, _
RichText:=True
Selection.MoveDown Unit:=wdLine, count:=4
Selection.Delete Unit:=wdCharacter, count:=1
Selection.Delete Unit:=wdCharacter, count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
The problem:
When I open the template from sharepoint this macro doesn't work anymore.
I think this is because Word changes the linked template. when I go to the developer tab and click on 'Document Template' the linked template is the following: 'C:\Users\xxx\AppData\Local\Temp\TemplateATA-8.dotm' (the 8 changes to a 9 the next time I open the template from SharePoint.)
When i work localy and change the link to the local location, there is no problem.
Can someone please help me?
Thanks
Nina
(I'm using Word 2013, but also older versions of Word have to be able to use the document.)
Problem solved. I changed the link to: Application.Templates( _
ActiveDocument.AttachedTemplate.FullName). _
Now it works perfectly!!

VB6 List and Delete All Files in Directory

I need to grab the names of all files in a directory, I am currently using this code:
Dim File As String
File = Dir$(Environ("AppData") & "\*.exe")
Do While Len(File)
MsgBox "Deleting: " & Environ("AppData") & "\" & File
Kill Environ("AppData") & "\" & File
File = Dir$
Loop
This works fine, however it does not display hidden/system files, or files with any attributes other than 'normal', how can I list files no matter their attributes?
I have tried this as well, which has the same outcome:
Kill Environ("AppData") & "\*.*"
The Dir function can take a second parameter for attributes:
File = Dir$(Environ("AppData") & "\*.exe", vbHidden & vbSystem)
You can fin more about the Dir function here.
I pretty much always use the Microsoft Scripting Runtime for file I/O from VB6. It just does more, and it does it better and more easily. One tiny downside is that your VB program is now dependent on the Scripting Runtime DLL (scrrun.dll), which you should add as a reference from within the VB6 IDE.
Here's an example that deletes all files from a folder.
' Note: This code is untested.
Sub Main()
DeleteAllFilesInFolder Environ("App_Data")
End Sub
Sub DeleteAllFilesInFolder(strFolder As String)
Dim fso As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File
Set fso = New Scripting.FileSystemObject
Set objFolder = fso.GetFolder(strFolder)
For Each objFile in objFolder.Files
objFile.Delete force:=True
Next
End Sub