I have pasted some code that looks like this:
Dto = new MyDto()
{
SessionId = sessionId.ToString(),
UserName = username,
License = allocateLicense
},
but the pasted version looks like:
Dto = new MyDto
()
{
SessionId =
sessionId.
ToString(),
UserName =
username,
License =
allocateLicense
},
I tried control-z (undo) and sometimes with simple pieces of code it reformats correctly but for other code it stays as above with line breaks.
So is there a way I can select the pasted code and reformat it so that the additional line breaks are removed?
If the problem is automatic formatting on paste you can of course disable it. If it's the other way around you can do the same as well..
Visual Studio > Tools > Options > Text Editor > C# > Formatting
appropriately set Automatically format on paste
This happens often when you copy code from PDF files or web pages.
I usually remove the unwanted formatting by pasting the code on a plain-text editor like notepad, then from notepad over to Visual Studio.
Related
In the Visual Studio 2013 editor, the following URL syntax works in C/C++ comment blocks - for single click navigation:
//
// http://bitbucket.org/foo/main.cpp#cl-123
//
The Visual Studio 2015 editor considers the fragment starting with # not to be part the URL. It does accept %23 instead of # but the server does not like it:
//
// http://bitbucket.org/foo/main.cpp%23cl-123
//
Is there a way to relax the URL encoding / syntax checking in VS 2015?
Solution: Surround the offending URL with " " ( ) or { }.
I am developing a Visual Studio package and I have written some code that will make a file in Solution Explorer dependant upon another file.
What this means is that it gives them the same relationship as code-behind files or designer files, where they appear nested under the parent file with a plus/minus icon.
+ MainForm.cs
- MainForm.cs
MainForm.Designer.cs
MainForm.resx
The code that I have written successfully and correctly modifies the underlying project file, however the change is not reflected in Solution Explorer until the project is closed and re-opened.
I'm looking for some code that will refresh or reload the project so that the change is visible in Solution Explorer immediately.
Further Information...
Here is the sudo code that demonstrates the mechanism by which I create the dependant file.
IVsBuildPropertyStorage vsBuildPropertyStorage = GetBuildPropertyStorage();
vsBuildPropertyStorage.SetItemAttribute(projectItemIdentifier, "DependentUpon", parentFileName);
I have also tried adding this in an attempt to get the project to reload, but it doesn't have any effect.
project.Save();
VSProject obj = project.Object as VSProject;
obj.Refresh();
AFAIK the only way of doing this is via automation of the Solution Explorer tool-window:
EnvDTE.DTE dte = ...;
string solutionName = Path.GetFileNameWithoutExtension(dte.Solution.FullName);
string projectName = project.Name;
dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate();
((DTE2)dte).ToolWindows.SolutionExplorer.GetItem(solutionName + #"\" + projectName).Select(vsUISelectionType.vsUISelectionTypeSelect);
dte.ExecuteCommand("Project.UnloadProject");
dte.ExecuteCommand("Project.ReloadProject");
Note that, if the project hasn't been saved, the user will get a dialog box prior to the "Project.UnloadProject" call.
Here is my code (with reactivating the old window):
public void RefreshSolutionExplorer(EnvDTE.Project activeProject, string captionOfActiveWindow)
{
DTE2 dte2 = activeProject.DTE as DTE2;
string solutionName = Path.GetFileNameWithoutExtension(dte2.Solution.FullName);
string projectName = activeProject.Name;
// Activate SolutionExplorer window
dte2.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate();
// Select your project to be updated
dte2.ToolWindows.SolutionExplorer.GetItem(solutionName + #"\" + projectName).Select(vsUISelectionType.vsUISelectionTypeSelect);
// Refresh SolutionExplorer window
dte2.ExecuteCommand("View.Refresh", String.Empty);
// Reactivate your old window
dte2.Windows.Item(captionOfActiveWindow).Activate();
}
I have a command line executable I built which is published on the network via ClickOnce. The main use of this tool is through Visual Studio as an external tool. When I set this up in Visual Studio I am able to set the command path to the shortcut under roaming data for my profile.
However, Visual Studio resolves this to a path such as:
C:\Users\ME\AppData\Local\Apps\2.0\CGR50YPV.W5E\RXBXM176.HH8\crea..tion_f423fce0316e1dfa_0001.0000_adecafbe6c6acba3\MyAppp.exe
So what happens is if I launch the exe and grab a new version, Visual Studio is still pointing at the old version (as indicated above). I can fix this by re-pointing the command value of my external tool to the shortcut of my exe, but this is a bit frustrating to deal with.
How can I make this work without having to update my command path every time?
You shouldn't access a ClickOnce application via the exe file. If you're going to do that, just xcopy the \bin folder of the application to the other machine. If you want to use the update features, you should always invoke the ClickOnce application by using the shortcut or by invoking the link to the deployment manifest on the webserver. (The deployment manifest is the application file). You can do a process.start on that link.
[edit -- add new info]
Ohhhhh, so you're accessing the shortcut in the folder under the user's profile? Am I getting that? Instead of looking for that one, can you point to the shortcut on the start menu? It will add one automatically when the user installs the application, if the application is online/offline. The shortcut is added to the start menu to the location of the Publishing Company / Product Name using those fields from the Options dialog.
I do this by setting the assembly information to the same values, and retrieving the assembly information programmatically. I always set the assembly description to be identical to the product name, and the assembly company to be the same as the publishing company. Then I can do this:
Assembly code = Assembly.GetExecutingAssembly();
string company = string.Empty;
string description = string.Empty;
if (Attribute.IsDefined(code, typeof(AssemblyCompanyAttribute)))
{
AssemblyCompanyAttribute ascompany =
(AssemblyCompanyAttribute)Attribute.GetCustomAttribute(code,
typeof(AssemblyCompanyAttribute));
company = ascompany.Company;
}
if (Attribute.IsDefined(code, typeof(AssemblyDescriptionAttribute)))
{
AssemblyDescriptionAttribute asdescription =
(AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(code,
typeof(AssemblyDescriptionAttribute));
description = asdescription.Description;
}
if (company != string.Empty && description != string.Empty)
{
string shortcutName =
string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Programs),
\", company, "\\", description, ".appref-ms");
}
(Sorry, I can't figure out how to make the code format prettier and show the indents properly, but you get the idea.)
The subject says it all. Is there an easy way to toggle the editability of a buffer in Visual Studio? This would be similar to the toggle-read-only command in Emacs.
I am not looking to change the file attribute ... just whether I can edit the file while it is open in Visual Studio. I am using 2008 and 2005.
Why would I want to do this? I tend to have several files open at the same time .... for days at a time sometimes (perhaps a bad habit) and I have +/- a char or few here and there without meaning to or noticing ... also worried about "the cat walking across the keyboard"
Besides ... an "ancient" code editor like emacs has it :) and I grew to expect the feature.
TIA!
There is an extension for Visual Studio called CodeMaid that will give you a Read-Only Toggle per file.
http://www.codemaid.net/documentation/#andmore
You can download it at http://visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496
You can use this piece of vba
Public Sub ToggleReadOnly()
Dim doc As Document
doc = DTE.ActiveDocument
If (doc.ReadOnly) Then
doc.ReadOnly = False
Else
doc.ReadOnly = True
End If
End Sub
Note: the msdn documentation specifically mentions that the property ReadOnly shouldn't' be used explicit but I verified that this works for me on vs.net 2005.
I also verified that the actual file attribute isn't changed.
I'm not aware of anything that will quickly achieve what you're looking for. Furthermore, I'm not really sure why you would need such a thing. Typically I use subversion to tell me which files have been changed and where they have been modified that way I can revert anything that doesn't belong.
Can you expand on your question a little to let us know what your usecase is?
If you really need to toggle readonly....perhaps you can:
Right click on the file
Select Open Containing Folder
Right click on the file and choose properties
Check the readonly checkbox
Start Tools->Macros->Macro IDE. Add new module (described here in details) and define there procedure as follows:
Imports EnvDTE
Public Sub SwitchReadOnly()
DTE.ActiveDocument.ReadOnly = Not DTE.ActiveDocument.ReadOnly
End Sub
Assign macro to keyboard key(described here in details). That's all.
Is there a way to always have LF line endings in Visual Studio? I can never seem to find it!
There'a an add-in for Visual Studio 2008 that converts the end of line format when a file is saved. You can download it here: http://grebulon.com/software/stripem.php
You don't have to install any plugins.
As mentioned here you can configure line endings in File -> Advanced Save options...
Yes, there is a way to always have LF line endings, at least in Visual Studio 2010 Pro.
Go to Tools | Options... | Environment | Documents
Then Enable the Check for consistent line endings on load option.
It works for me.
Visual Studio 2008 doesn't retain the advanced save options after the solution is closed. I would be willing to hand edit a lot of files if that would make it work consistently, but I am not willing to change all of the settings every time I open VS.
This is too bad. Since VS does support forcing the line-endings to whatever is desired in the backend, its just not hooked up properly in the UI. Maybe Microsoft will fix this isn a service pack.
There's a plugin to VS called Strip'Em where you can choose which kind of new line type you want to auto convert all the line endings to when saving.
(You can choose between LF, CRLF, CR.)
I seem to have found a method by accident and found this article attempting to correct it (I want Windows CRLF EOL)! Doing the following results in UNIX (LF only) line endings for me.
SaveFileDialog^ dialog = gcnew SaveFileDialog();
System::Windows::Forms::DialogResult DR;
dialog->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
dialog->FilterIndex = 2;
dialog->RestoreDirectory = true;
dialog->DefaultExt = "txt";
DR = dialog->ShowDialog(this);
if ( DR == System::Windows::Forms::DialogResult::OK )
{
// Get the page (tab) we are currently on
System::Windows::Forms::TabPage ^selPage = this->tabControl1->SelectedTab;
// Note: technically the correct way to look for our control is to use Find and search by name
// System::Windows::Forms::RichTextBox ^selText = selPage->Controls->Find("rtb", false);
// I only add one control (rich text) so first control ([0]) must be it
System::Windows::Forms::RichTextBox ^selText = safe_cast<System::Windows::Forms::RichTextBox^>(selPage->Controls[0]);
// Just let a Windows forms method do all the work
File::WriteAllText(dialog->FileName, selText->Text);
}