Code Generation and T4 Text Templates

http://msdn.microsoft.com/en-us/library/bb126445.aspx

http://brochure.jrcs3.com/2011/03/t4-template-tour-of-first-gear.html

Include directive

Quite useful
<#@ include file=”TextTemplateVB6.t4″ #>
<#@ include File=”$(SolutionDir)\CodeDBGenerator\TextTemplateLibrary\TextTemplate\GeneratedHeader.t4″ #>

This uses actual file location, which may be different to how it appears in Solution explorer.

Note: the included file cannot have a <#@ template language=”VB” #> on it.
Probably want to rename it .t4 and remove the custom tool, so that it does not generate it’s own file.
After it has been included then Class Feature Blocks may be put in here for re-use by many templates. <#+

If you want it separately and also included elsewhere then a strategy I came up with was to have have the file without the <#@ template language=”VB” #> and then a separate file which was just:

<#@ template language=”VB” #>
<#@ include file=”TextTemplateVB6.t4″ #>
Be careful on .t4 file, you probably want to not have a custom tool. This can be done by creating a standard text file and changing it’s file extenstion to .t4 or create a text template file and then remove the Custom Tool from files properties. See:  Run Custom Tool

 

To use T4 within a program

To have a form that generates code say in a text box. Then:

  1. Set “Custom Tool” of text template to “TextTemplatingFilePreprocessor” and Custom Tool Namespace to say “My.Templates”
  2. Dim code = New My.Templates.PreTextTemplate1
    GeneratedCodeTextBox.Text = code.TransformText

 

To use If.

For instance with include file then:

<# If ParameterList(4) = 1 Then #>
<#@ include file=”SetRowBase.tt” #>
<# End If #>

 

More blog TODO

… looks potentially useful in some circumstances

Directives
http://msdn.microsoft.com/en-us/library/bb126421.aspx

To read
http://msdn.microsoft.com/en-us/library/gg251243.aspx

Run Custom Tool

Solution Folder > Point at file > Right click Properties
Custom Tool – Add or remove a custom tool name here.

Examples

  • TextTemplatingFileGenerator
  • TextTemplatingFilePreprocessor

Useful Transact SQL sp procedures

sp_defaultdb ‘login’, ‘master’
SQL Server 2005. If you detach the default database from the server, then you may experience unable to login errors, for instance on attach.
Use the above to change the default database and you will then be able to login.
For simple connection > Options > Connection Properties > Connect to database > Change from <default> to another still attached database or master

Windows Explorer remove add-in context menu

 

Export suspect registry key from. Then delete test. If not better then import saved.

HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers

Subversion Windows Explorer Add-In Enable/Disable

 

http://www.howtogeek.com/howto/21106/how-to-enable-or-disable-tortoisesvn-menus-easily/

This works

Change IP address of a local (home) pc

This example is using Wanadoo Inventel Wireless Magic on Windows XP
The aim in this case is to change the IP address from using 192.168.1.x to using 192.168.0.x

Start > All Programs > Wanadoo > Configure the Live Box
Login > Configuration > Advanced > Network
Change LAN IP address, Broadcast LAN IP address, and 2 x DHCP addresses
Submit and wait for it to reset

My Network Places > View network connections > Right-click on Wireless Network Connection > Disable > Enable
This will force it to look for new IP address. Success

See Connection to SQL Server over VPN

Connection to SQL Server over VPN

 

Get VPN connection IP address from IT server administrator
Set up VPN and login
Connect to SQL on local PC using SSMS or Visual Studio using SQL Authentication login and password
The server name to use in SSMS will be an IP address on the Network that you have used VPN to get to. You may or may not need to add \InstanceName.
It is not uncommon for this internal IP address system to be 10.0.0.x where x is the computer number
So format may be 10.0.0.x or 10.0.0.x\InstanceName

Special Cases
If the VPN internal IP address system uses 192.168.1.x then be careful that your local PC is not using 192.168.1.x
If it is then need to change the local PC IP address system to use 192.168.0.x

See Change IP address of a local (home) pc

‘Settings’ is not a member of ‘My’

SOLVED

Try adding the namespace, so:

My.Settings.conAName
becomes
[Namespace].Settings.conAName

Microsoft.Common.targets (1360): Found conflicts between different versions of the same dependent assembly

Problem

Warning : “Found conflicts between different versions of the same dependent assembly”

Not enough information

Solution – Method

The verbosity of builds may be changed in Visual Studio > Tools > Options > Projects and Solutions > Build and Run > MSBuild Project output verbosity. May need to go to at least detailed. Then use the output window to get more information.
The verbosity may also be changed in the VS-TFS build.

Then search in the Output for “conflict”, and underneath it states:

“References which depend on “… new version
“References which depend on “… old version

Make them match.

Solution – Binding Redirect

Optionally check-in the file containing the app.config.

If you double click on the warning then you may get a message:

“One or more dependent assemblies have version conflicts.
Do you want to fix these conflicts by adding binding redirect records in the app.config file?”

If you click OK, then use source code control to compare the app.config you will get a change in the newVersion setting

<runtime>
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<dependentAssembly>
<assemblyIdentity name=”EntityFramework” publicKeyToken=”B77A5C561934E089″ culture=”neutral” />
<bindingRedirect oldVersion=”0.0.0.0-4.4.0.0″ newVersion=”6.0.0.0″ />
</dependentAssembly>
</assemblyBinding>
</runtime>

This Post History

VS-TFS Build was reporting this error for a long time, but not indicating precisely which file was causing the problem

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (1360): Found conflicts between different versions of the same dependent assembly

Generally have found the problem to be on a project which references another project, where both projects use the same references. One may get out of sync with the project being built.

Found the problem difficult to find. Not entirely sure what the problem was:
The build server had a copy of version 9 of Microsoft.VisualBasic.PowerPacks.Vs in c:\Program Files\Common Files\Microsoft Shared\…
instead of version 10.0 listed in some projects.
I checked that version 10 was installed on the build server, then removed the version 9 from this pc.
Could have perhaps considered making the PowerPack reference copy local.

Also try working out any references listed in the problem project which are also used by referenced projects and include a reference to the problem project. I have found that where Visual Studio builds projects without the referenced project references, MSBuild seems to need them in the target project as well. This was not in fact the case in my resolution here.

Example solved 15-Mar-2011 was System.Windows.Forms.DataVisualization was version 3.5.0.0 in a user control. Upgraded all to 4.0.0.0.

See http://stackoverflow.com/questions/1871073/resolving-msb3247-found-conflicts-between-different-versions-of-the-same-depend

ODBC connection to SQL Server 2008 R2

On ODBC  using SQL Native Client.
Many possible problems. But consider trying with Server Firewall off. If this is successful then consider the following changes on firewall which have worked for me.

Firewall settings on server are:

http://technet.microsoft.com/en-us/library/ms175043.aspx

  • On the Start menu, click Run, type firewall.cpl and then click OK.
  • In the Windows Firewall dialog box, click the Exceptions tab, and then click Add Port.
  • In the Add a Port dialog box, in the Name text box, type SQL Server <instance name>.
  • In the Port number text box, type the port number of the instance of the Database Engine, such as 1433 for the default instance.
  • Verify that TCP is selected, and then click OK.
  • To open the port to expose the SQL Server Browser service, click Add Port, type SQL Server Browser in the Name text box, type 1434 in the Port Number text box, select UDP, and then click OK.
    NoteNote
    To allow named pipes access through the firewall, you must also enable File and Printer Sharing through the firewall.
  • —————

    Also Firewall on server must add program SQLServer.exe which is at <program files><Microsoft SQL Server><MSSQL10_50.Instance Name\MSSQL\Binn\sqlservr.exe

    ————-

    Prefer not using older ODBC SQL server, but if do then on client configuration dynamically chosen ports is relevant