Are the <References> and <Imports> tags supposed to work for C# code snippets? - visual-studio-2017

Microsoft has conflicting documentation for custom code snippets. According to this page:
You can add a reference to a project by using the References element, and add an Imports declaration by using the Imports element. (This works for C# as well.)
But then, the schema reference documentation contradicts that and says:
The Imports element is only supported for Visual Basic projects.
I'm currently trying to use the <References> and <Imports> elements for a C# snippet, and it works with the shortcut, but it does not add the using statements or references.
Here is the XML for the .snippet file that I'm testing with:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Test snippet</Title>
<Author>Test Author</Author>
<Description>Test Description</Description>
<Shortcut>test1</Shortcut>
</Header>
<Snippet>
<Code Language="CSharp">
<![CDATA[Console.WriteLine("Hello World.");]]>
</Code>
</Snippet>
<References>
<Reference>
<Assembly>System.Windows.Forms.dll</Assembly>
</Reference>
<Reference>
<Assembly>System.Drawing.dll</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>System.Windows.Forms</Namespace>
</Import>
<Import>
<Namespace>System.Drawing</Namespace>
</Import>
</Imports>
</CodeSnippet>
</CodeSnippets>
Are <References> and <Imports> really supported by C#? Or is it only supported by Visual Basic?

It does work for C# as well, you just have to put the References and Imports inside of the <Snippet></Snippet>.
Example:
<Snippet>
<References>
<Reference>
<Assembly>System.dll</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>System.ComponentModel</Namespace>
</Import>
</Imports>
<Code Language="CSharp">
<![CDATA[
]]>
</Code>
<Declarations>
<Literal>
<ID>ModelClass</ID>
<Default>object</Default>
</Literal>
</Declarations>
</Snippet>
Read more here: msdn Walkthrough on Code Snippets

Related

I need to remove the attribute tags <types> </types> without any value in an xml file using ant script

I need to remove the attribute tags without any value in an xml file using ant script
Below is the XML I have:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>DoNothingTest</members>
<name>ApexClass</name>
</types>
<types>
</types>
<types>
</types>
<types>
</types>
<types>
</types>
<version>42.0</version>
</Package>
All the tags that does not have a nesting tag or value should be removed from this xml . The output should look like below:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>DoNothingTest</members>
<name>ApexClass</name>
</types>
<version>42.0</version>
</Package>
How can I achieve this using ANT script?
I am using the below ant script to perform the job, however, it trims only one occurence of 'types' tag.
<!--Format the generated XML file -->
<target name="formatXML" depends="generatePackage.xml">
<property name="final-xml.file" value="temp/src/package.xml"/>
<for param="src-xml.absolute-path" list="${final-xml.file}">
<fileset dir="temp/src/" includes="*.xml"/>
<sequential>
<replaceregexp file="${final-xml.file}"
flags="s"
match="\s*(?:<\/([a-z]+)>)(\s*<\1>)"
replace=""/>
</sequential>
</for>
</target>
How to iterate over the xml file and replace all occurences of 'types' tags?
You can invoke an XSLT transformation from Ant using the XSLT ant task. A stylesheet to remove empty <types> elements in namespace http://soap.sforce.com/2006/04/metadata consists of a boilerplate identity rule to copy all elements unchanged, plus the rule
<xsl:template match="x:types[not(*) and not(text()[normalize-space()])]"
xmlns:x="http://soap.sforce.com/2006/04/metadata"/>

Error Could not load file or assembly 'Nlog, version=4.0.0.0, culture=neutral, publickeytoken=5120e14c030593c'

I have a 2 Sharepoint projects Sharepoint-Svr-App & Sharepoint-svr-Job in one solution and both projects have the NLog reference. Publishing those two projects generates the corresponding *.wsp files without any issue. When I deploy the solution, Sharepoint-svr-App gets deployed without any issue but Sharepoint-Svr-Job failes with Error:
Could not load file or assembly 'Nlog, version=4.0.0.0, culture=neutral, publickeytoken=5120e14c030593c'
Please find the attached screenshot here
Entries inside Sharepoint-Srv-App.csproj are given below:
<ItemGroup>
<Reference Include="NLog">
<HintPath>packages\NLog.4.4.5\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="NLog.Web">
<HintPath>packages\NLog.Web.4.4.0\lib\net35\NLog.Web.dll</HintPath>
</Reference>
<ItemGroup>
and Sharepoint-Srv-Job.csproj looks like
<ItemGroup>
<Reference Include="NLog">
<HintPath>..\Sharepoint-Svr-App\packages\NLog.4.4.5\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="NLog.Web">
<HintPath>..\Sharepoint-Svr-App\packages\NLog.Web.4.4.0\lib\net35\NLog.Web.dll</HintPath>
</Reference>
<ItemGroup>
packages.config file in both projects is same like below:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="4.4.5" targetFramework="net45" />
<package id="NLog.Config" version="4.4.5" targetFramework="net45" />
<package id="NLog.Schema" version="4.4.5" targetFramework="net45" />
<package id="NLog.Web" version="4.4.0" targetFramework="net45" />
</packages>
Issue got resolved
Try to add your external dlls into your solution and check.
Go to your Package.package->Advanced.
Here is one thread for your reference.
https://social.technet.microsoft.com/Forums/office/en-US/7642b88a-4046-4429-a9d2-e2088c86f3fd/deploying-custom-dlls-in-sharepoint-2013?forum=sharepointadmin

how to generate xml file using libxml2 in c++?

I want to have following xml file:
<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE people SYSTEM "XMLSpyDTD.dtd">
<report>
<Start>
<date format="ddMMyy" val="Tue Jun 09 2015
" />
<time format="hhmm" val="11:43:06 " />
</Start>
<test name="Testadd" executed="Yes">
<discription>
<![CDATA[Add two numbers]]>
</discription>
<targets>
<target threaded="false">C++</target>
</targets>
</test>
</report>
So, kindly suggest me how may i generate it using libxml2 in c++?

Creating custom magento webservices

I'm having some trouble creating some custom web services in Magento. I'm trying to get the module configured properly and I can't seem to make the web services I've defined in the api.xml file show up under the user role setup in the admin area.
I've defined a custom module in app/etc shown here
ctp_GiftCards.xml:
<?xml version="1.0"?>
<config>
<modules>
<ctp_GiftCards>
<active>true</active>
<codePool>local</codePool>
</ctp_GiftCards>
</modules>
</config>
The module code is located in app/local/ctp/GiftCards/
Here is an example of the etc/api.xml:
<?xml version="1.0"?>
<config>
<api>
<resources>
<GiftCards translate="title" module="ctp_GiftCards">
<title>GiftCard webservices</title>
<acl>GiftCards/GiftCard</acl>
<methods>
<update translate="title" module="ctp_GiftCards">
<title>updates a giftcard account</title>
</update>
</methods>
<faults module="ctp_GiftCards">
<invalid_data>
<code>100</code>
<message>giftcard data invalid</message>
</invalid_data>
<card_pool_error>
<code>101</code>
<message>card pool for entry not updated</message>
</card_pool_error>
<cache_error>
<code>102</code>
<message>cache not reset</message>
</cache_error>
</faults>
</GiftCards>
</resources>
<acl>
<resources>
<GiftCards translate="title" module="ctp_GiftCards">
<title>GiftCards</title>
<sort_order>6</sort_order>
<GiftCard translate="title" module="ctp_GiftCards">
<title>GiftCard</title>
<update translate="title" module="ctp_GiftCards">
<title>Update</title>
</update>
</GiftCard>
</GiftCards>
</resources>
</acl>
</api>
</config>
and the etc/config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<ctp_GiftCards>
<version>0.1.0</version>
</ctp_GiftCards>
</modules>
<global>
<models>
<GiftCard>
<class>CTP_GiftCards_Model</class>
</GiftCard>
</models>
</global>
</config>
Any help would be much appreciated.
--edit--
I'm using mangeto pro 1.10
Don't use capital letter (GiftCards) in the name of xml tag inside the node. Moreover, your module's name contains both underscope (_) and capital letter (ctp_GiftCards) which will lead Magento to misunderstand.

Magento 1.5.01 - I am unable to load a template after overriding the customer module

This is my first post here, so please forgive me in advance :)
I've been working on overriding the Customer module for some specific
functionality depending on the user group; I want to duplicate and
append to the user registration form that targets the specific user
group.
I have successfully overridden and extended my way through the
controller, model, and block classes that I would like to use, however
when I override the block class, the layout i'm pointing to is no
longer rendered.
Here's the relevant chunk of the layout code:
<customer_account_vcreate translate="label">
<label>Customer Account Registration Form</label>
<!-- Mage_Customer -->
<remove name="right"/>
<remove name="left"/>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
<block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label">
<label>Form Fields Before</label>
</block>
</block>
</reference>
</customer_account_vcreate>
I know that it just points to the regular block/template right now, but even that isn't loading. The block loads just fine (I can output from the constructor), it just seems that the layout file is not being loaded anymore.
I've also tried to override the login form with similar problems, can anyone help?
Geoff
EDIT -
Here's a more complete question for the login block:
Here's my config:
<?xml version="1.0"?>
<config>
<modules>
<Izoox_Customer>
<version>1.0.1</version>
</Izoox_Customer>
</modules>
<frontend>
<routers>
<customer>
<args>
<modules>
<Izoox_Customer before="Mage_Customer">Izoox_Customer_Customer</Izoox_Customer>
</modules>
</args>
</customer>
</routers>
<layout>
<updates>
<customer>
<file>izooxcustomer.xml</file>
</customer>
</updates>
</layout>
</frontend>
<global>
<blocks>
<customer>
<rewrite><form_login>Izoox_Customer_Block_Form_Login</form_login>
</rewrite>
</customer>
</blocks>
</global>
</config>
It works when I remove the block code from the above config, except then I'm not getting any of my custom code from the block.
Above I have overridden the Customer module to use my own code here, and have overridden the customer_login block with my own block. I can see that the custom block loads by echoing out of the _prepareLayout() function, but the view file (login.phtml) doesn't seem to load. Here's the layout (izooxcustomer.xml), which also loads fine.
<customer_account_login translate="label">
<label>Customer Account Login Form</label>
<!-- Mage_Customer -->
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
</reference>
</customer_account_login>
Am I missing something, or is this just not possible?
Thanks,
Geoff
Looks like you have your main layout tag misspelled. It should be <customer_account_create>. You have a 'v' in there before create.