Visual Studio code snippets extra line - visual-studio

I am using a code snippet inside Visual Studio (Community 2015) to automate the line Debug.LogFormat("");. The snippet is working but it adds a extra empty line (enter) at the start so using the snippet with logtabtab will result in the following code:
// blank line
Debug.LogFormat("");
instead of
Debug.LogFormat("");
Here is the XML of the snippet I use:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Unity LogFormat</Title>
<Author>Faas</Author>
<Shortcut>log</Shortcut>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>Message</ID>
<ToolTip>Message</ToolTip>
<Default></Default>
</Literal>
</Declarations>
<Code Language="CSharp"><![CDATA[Debug.LogFormat("$Message$");]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

I can fix the problem by placing a $end$ in the Code element. I don't know the root cause. Just have a try.
<Code Language="csharp"><![CDATA[Debug.LogFormat("$Message$");$end$]]>
See more document about Code element here.

Related

ASP Classic Snippets in Visual Studio 2013

How I should create asp classic snippets and use they in visual studio? I follow some tutorials on the internet but doesn't work at all:
This is a sample from my snippet:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Total de registros a serem exportados.</Title>
<Author>Lucas Luan de Melo Pereira</Author>
<Description>Implementa a busca ao parametro de limite de linhas a serem exportadas.</Description>
<Shortcut>snpTot</Shortcut>
</Header>
<Snippet>
<Code Language="VBScript">
<![CDATA[
'---------Total de registros a serem exportados---------------
response.write("Awesome feature!")
'-------------------------------------------------------------
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
In VS, I'm importing inside VB option (Code Snippets Manager). But when try to use don't work also another question, this will be called by Intellisense? There's no option of snippets im my *.asp files.

Joomla template folder not showing in template manager

I am trying to create a template.I have created a folder for template in templates folder and also created two files index.php and templateDetails.xml
My index.php has following code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
<head>
<jdoc:include type="head" />
</head>
<body>
<jdoc:include type="component" />
</body>
</html>
and templateDetails.xml has following code which yes I copied because beginner.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE install PUBLIC "-//Joomla! 1.5//DTD template 1.0//EN"
"http://dev.joomla.org/xml/1.5/template-install.dtd">
<install version="3.1.5" type="template">
<name>template _tut</name>
<creationDate>31-01-2009</creationDate>
<author>Nettut Fan</author>
<authorEmail>your#email.com</authorEmail>
<authorUrl>http://www.siteurl.com</authorUrl>
<copyright>You 2009</copyright>
<license>GNU/GPL</license>
<version>1.0.0</version>
<description>Template Tut</description>
<files>
<filename>index.php</filename>
<filename>templateDetails.xml</filename>
<filename>css/template.css</filename>
</files>
<positions>
<position>breadcrumb</position>
<position>left</position>
<position>right</position>
<position>top</position>
<position>user1</position>
<position>user2</position>
<position>user3</position>
<position>user4</position>
<position>footer</position>
</positions>
</install>
My joomla version is 3.1.5 and despite doing above mentioned steps my template folder is not showing in template manager.
You need to install the template to register it completely.
There are 2 ways of doing this:
Download your files, zip them up and install it as you would any other extension.
In the Joomla backend, go to "Extension Manager", then "Discover". This will detect uninstalled extensions and should bring your template up in the list. check it and install it
Hope this helps

dont show modules

I am doing a joomla 2.5 project
I put this <jdoc:include type="modules" name="izquierdo" style="none"/> and it shows me nothing.
The positions in my template is this:
<positions>
<position>izquierdo</position>
<position>extranet</position>
<position>menuPrincipal</position>
The status of this module is public.
Any ideas, am I miss something?
I found something strange.
if I put my route and at the end add ?tp=1 it shows me all my postions and it shows me my module (I see the image and other thinks), but with the normal router (without ?tp=1) I don't see anything.
This is my xml template:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE install PUBLIC "-//Joomla! 1.6//DTD template 1.0//EN" "http://www.joomla.org/xml/dtd/1.6/template-install.dtd">
<extension version="2.5" type="template" client="site">
<name>arquero</name>
<creationDate>10/10/09</creationDate>
<author>Ron Severdia</author>
<authorEmail>mpiedra#edosoftfactory.com</authorEmail>
<authorUrl>http://www.kontentdesign.com</authorUrl>
<copyright>Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<version>2.5.0</version>
<description>ARQUERO_XML_DESCRIPTION</description>
<files>
<folder>html</folder>
<folder>css</folder>
<folder>images</folder>
<folder>js</folder>
<filename>index.php</filename>
<filename>index.html</filename>
<filename>templateDetails.xml</filename>
<filename>ajax.php</filename>
<filename>component.php</filename>
</files>
<positions>
<position>izquierdo</position>
<position>extranet</position>
<position>menuPrincipal</position>
<position>carrusel</position>
<position>noticias</position>
<position>footer</position>
<position>debug</position>
</positions>
</extension>
It seems to be fine your template. But try style="xhtml" on your jdoc statement.
And another guess is please check again the assignment of pages for your module from the backend. Most probably you might select "No pages" for the module assignment.
Thank you.

Visual Studio 2008 code snippet doesn't add Reference Assembly and/or Import Namespace

I'm developing some code snippet, and I experienced that Visual Studio doesn't automatically add Reference to specified assembly and doesn't import the specified namespace.
My snippet definition is:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MyTryCatch</Title>
<Shortcut>myTryCatch</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>MyAssembly.dll</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>MyNamespace</Namespace>
</Import>
</Imports>
<Declarations>
<Object Editable="true">
<ID>Message</ID>
<Type>String</Type>
<ToolTip>Error message</ToolTip>
<Default>message</Default>
<Function></Function>
</Object>
</Declarations>
<Code Language="csharp" Kind="" Delimiter="$">
<![CDATA[try
{
}
catch (Exception exception)
{
throw new MyNamespace.MyException("$Message$", exception);
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
</CodeSnippets>
Note that I'm referencing a custom MyAssembly.dll that is visible from "Add Reference" popup (.NET Tab).
When I use the above snippet by myTryCatch shortcut, I'm able to see the snippet code but no Reference added and no Import made.
How I can fix or debug this issue?
Thanks in advance!
It sounds like the problem is your choice of language. Only VB.Net supports reference assemblies and importing of namespaces from a code snippet. The C# engine will ignore these elements.
Reference: http://msdn.microsoft.com/en-us/library/ms171438.aspx

Can I define custom "surround with" templates in Visual Studio 2008?

Can I define custom "surround with" templates in Visual Studio 2008?
Here you go, this is an example to set everything selected inside {}
In tools, codesnipet manager.
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>{}</Title>
<Shortcut>{}</Shortcut>
<Description>Code snippet for {}</Description>
<Author>Sérgio</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Code Language="csharp"><![CDATA[{
$selected$ $end$
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
In the event anyone else visits this question searching for more examples, here's my snippet to surround the block of code with a stopwatch:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Stopwatch</Title>
<Shortcut>SW</Shortcut>
<Description>Code snippet for Stopwatch</Description>
<Author>Bernhard Hofmann</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Code Language="csharp"><![CDATA[var tacho = new System.Diagnostics.Stopwatch();
tacho.Start();
$selected$ $end$
tacho.Stop();
System.Diagnostics.Trace.WriteLine(string.Format("Elapsed: {0}", tacho.Elapsed));
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Also, if you save it as Stopwatch.snippet in My Documents\Visual Studio ????\Code Snippets\Visual C#\My Code Snippets, then it'll automagically appear in Visual Studio without needing to visit the Tools menu.
I have an example for you. This snippet will surround the selected text with <![CDATA[...]]>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Surround in CDATA</Title>
<Author>Sten Hougaard, 2010 - http://www.netsi.dk/wordpress</Author>
<Shortcut>shortcut</Shortcut>
<Description>Surrounds selected data in CDATA</Description>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<Default>value</Default>
</Literal>
</Declarations>
<Code Language="XML">
<![CDATA[<![CDATA[$selected$]]><![CDATA[]]]><![CDATA[]]]><![CDATA[>]]>
</Code>
</Snippet>
</CodeSnippet>
The steps to make this example are this:
Copy and paste these into a new XML file in Visual Studio
Save it anywhere as for instance: "SnippetXML_SurroundWithCDATA.snippet"
Open "Tools > Code Snippet Manager"
Click "Import..." and locate the file you just saved, choose it and click "open"
You now have the option to choose where it should be possible to "run" the snippet. Choose one or more "scenarios"
The snippet is now ready for use. Try it using a relevant scenario, for instance a XML file. Select some data and click Ctrl+K and Ctrl+S (or go through the menu). Locate the snippet and voila - your data has been surrounded with CDATA.

Resources