Visual studio merge problems with new line - c#

I'm having trouble with automerge i Visual Studio 2017.
When i try to add or remove a line break in my code, git sometimes refuses to automerge the file and I have to accept every single added or removed line break.
Old code:
if (someThing != null)
{
if (presentation)
{
New code:
if (someThing != null)
{
if (presentation)
{

Related

Fixing identation after and if statement Visual Studio 2019 programming in C#

After I type if (view=="") { and press Enter, VS formats and indents the curly braces to this:
if (view == "")
{
}
How can I change the settings in Visual Studio 2019 to just have it like this
if (view == "")
{
}
I've been looking and trying different combinations and can't seem to find the setting.
If you want to get the format you need, you can refer to the parameters of this option:
Tools>Options>Text Editor>C#>Code Style>Formatting>Indentation, uncheck the option ”Indent open and close braces”.

visual studio 2017 adds new line before semicolon after while

My visual studio 2017 auto formats following c# code:
while (source[--start] != '\"');
into:
while (source[--start] != '\"')
;
I haven't found any related settings which would be related to this rule.
Why does it add new line and tab before semicolon in this case?
Thank you.

Node not part of list Exception after removing node?

Here is a simple version of my code.
While (node != null && QtyAvailable > 0)
{
int OldQty = node.Value.NeedQty;
If (OldQty > 0)
{
int usedQty = node.Value.AddQTY(QtyAvailable);
}
QtyAvailable -= (OldQty - node.Value.NeedQty);
If (node.Value.NeedQty == 0)
{
MyList.Remove(node);
}
node = node.next;
}
Anyway, I have a LinkedList (doubly linked) with some basic data.
I update the nodes as needed and if a node is used and is not needed any more I delete the node. However, every once in a while I get an exception saying something like node is not part of list right after the Remove(node) command.
I am using VS2012 and I find it interesting that the highlighted line for the exception is the line after the remove command, something that I have seen for many exceptions in 2012 but not all.
This exception is extremely rare, but I think this error should not be possible and is a bug.
I am using VS2012 with the latest updates, making a Forms application with C#. Compiling for Debug X86 on a Win 7 64-bit machine. This error also occurs if I compile to X64. I use x86 so I can do debug-time editing if needed.

Adding existing project into new VS2012 solution programmatically fails

We have the following code in wizard to add existing project to a new solution:
//generating files
if (dte.Solution.Projects.Count < 1) // Solution is empty or doesn't exist
{
dte.Solution.Create(oneFolderHigher(Params.OutputDir, solutionName),
solutionFileName(solutionName));
}
// adding created project to solution
dte.Solution.AddFromFile(Path.Combine(Params.ProjectRootFolder,
Params.ProjectName + ".csproj"));
It works just fine under MS Visual Studio 2010, but fails under 2012 (I experimented with second parameter):
System.Runtime.InteropServices.COMException (0x80004004): Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
at EnvDTE.SolutionClass.AddFromFile(String FileName, Boolean Exclusive)
at Wizard.Generator.NewProjectGenerator.Generate(Action`1 logMessage)
at Wizard.Forms.WizardForm.Finish()
After this error I'm adding the new project to the solution manually and everything works OK. But we can not just say, "Sorry, we can not add newly generated project for you so please add it by yourself."
MSDN proposes:
You can use the LaunchWizard method rather than AddFromFile to execute a wizard if you want to suppress its UI during execution. LaunchWizard has a parameter that allows you to disable the UI.
But this method requires some wizard file, so it can not be a solution.
Could someone help?
Wizard is running from "New -> Project" menu.
Here the workaround for the issue (proposed by my boss):
Before adding the project to solution, project file should be converted to
VS2012 format.
But code is little ugly:
using (StreamReader sr = new StreamReader(newFile))
using (StreamWriter sw = new StreamWriter(projectFile, false, Encoding.UTF8))
{
while (sr.Peek() >= 0)
{
string s = sr.ReadLine();
if (s.Contains("<Project ToolsVersion=\"4.0\""))
{
s = s + Environment.NewLine + importProject;
}
... and so on
Maybe someone knows the way to do it awesome? I mean converting. I'll let the question to be unanswered some time. Waiting for your comments.

How to programmatically add a custom component to Visual Studio toolbox?

I am creating an installer for a custom SSIS component that we have written. I would like to add the custom component automatically, rather than asking the user to manually add it.
I'm trying to do this with this code:
public void AddToolboxItem(string toolboxTabName, string toolBoxItemName, string toolBoxItemPath) {
Type dteReference;
EnvDTE.ToolBox toolBox;
EnvDTE80.ToolBoxItem2 addedToolBoxItem;
// Get a reference to the visual studio development environment.
dteReference = Type.GetTypeFromProgID("VisualStudio.DTE.9.0");
if(dteReference != null) {
// Get a reference to the toolbox of the development environment.
EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)Activator.CreateInstance(dteReference);
toolBox = (EnvDTE.ToolBox)dte.Windows.Item("{B1E99781-AB81-11D0-B683-00AA00A3EE26}").Object;
// Loop through all tab pages to find the toolbox tab page that was specified
// in the toolboxTabName parameter.
foreach (EnvDTE80.ToolBoxTab2 toolBoxTab in toolBox.ToolBoxTabs) {
// Is this the right toolbox?
if(string.Compare(toolBoxTab.Name, toolboxTabName, true) == 0) {
// First check if the component is not already in the toolbox:
bool found = false;
foreach(EnvDTE80.ToolBoxItem2 toolBoxItem in toolBoxTab.ToolBoxItems) {
if (string.Compare(toolBoxItem.Name, toolBoxItemName, true) == 0) {
found = true;
break;
}
}
// The toolbox item is not in the toolbox tab, add it:
if (!found) {
addedToolBoxItem = (EnvDTE80.ToolBoxItem2)toolBoxTab.ToolBoxItems.Add(
toolBoxItemName,
toolBoxItemPath,
EnvDTE.vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
}
break;
}
}
}
}
I can get a reference to the "Data Flow Transformations" ToolBox Tab, but adding an item fails without an exception or error.
I call this function with the parameters:
toolboxTabName = "Data Flow Transformations"
toolBoxItemName = "Special Test Component"
toolBoxItemPath = "c:\Program Files\Microsoft SQL Server\100\DTS\PipelineComponents\mdTest.dll"
As a sanity check, I tried using the vsToolBoxItemFormatDotNETComponent enumeration as Add()'s third parameter. This causes Add to return a valid object (ie, success), but the new item does not appear on the tool box. I suspect there is some sort of 'save' operation that may be necessary (even if I get the Add() to work properly).
Is there any way to programmatically add a SSIS component to the
toolbox?
Same question can also be found in the MSDN forums and it has been answered there by an MVP, Moderator. I am pasting the link to the answer provided in MSDN forums so that others stumbling on this question can know what the answer is.
Programmatically Add an SSIS Component to the Toolbox (social.msdn.microsoft.com)

Categories

Resources