Sunday, April 28, 2013

Check SQL Server Installed Components

Once in while i get to a client that performs the TFS installation on his own, generally most of them do a bad installation (maybe i just go to the bad ones....)
the first thing i do is to check the SQL installation.
basically there are 2 ways:
1. Add/Remove Programs (Slow and painfully...)
2. SQL Server features discovery Report (short and informative)

to get to the report, we Open "SQL Server Installation Center"
 

 
Click on "Tools->Installed SQL Server features discovery Report"
 
you'll get an HTML report of all the features installed on the machine with their version.

SQL Server Name Update

once in a while i encounter clients that only after the installation of the SQL rememeber that the server name is not what they wanted.....
 
normally we had to reinstall the whole server again. but luckly we can update the SQL Server name After the machine change (connection to TFS after rename is a different issue...)
 
run the following in SSMS:
  1. run "Select @@servername" to verifiy the current server name
  2. run the following script to update the server name 
  3.          sp_dropserver 'old_name'
             go
             sp_addserver 'new_name','local'
             go
  4. Restart SQL Server service. I prefer the command prompt for this, but you can just as easily do it in Services under the Control Panel
    • net stop mssqlserver
    • net start mssqlserver
  5. Then after that is done run "select @@servername" to check the new name
 
 
 
 
 
 
 

How To: Find the SQL Version that is Installed

I Get to do a lot of TFS upgrades and migrations. there is one critical element in these actions,
that is the SQL Server, installation of a wrong version of SQL or missing some updates will cause problem restoring the databases and a big headache

so first we can use this query to check service pack and product edition (Developer / standard / Enterprise)

SELECT SERVERPROPERTY('productversion'),SERVERPROPERTY('productlevel'),SERVERPROPERTY('edition')

and for a more specific identification we can take the Version that is written in the SSMS
and check it against this site: http://sqlserverbuilds.blogspot.com/
this site contains a list of all patches and their corresponding version

Saturday, April 13, 2013

Web Deployment in TFS2012 - Part 2

In the previouse post i have shown how to publish.
this we publish the whole site, but what if i need external resources or exclude some config files?
so i looked around good people and here is what i found (also validated):

Adding to the Deployment
 <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>
  </PropertyGroup>
 
  <Target Name="CustomCollectFiles">
    <ItemGroup>
      <_CustomFiles Include="D:\Dev\W2012TFS2012Prd\DefaultCollection\Test\MySites\MvcApplication\Properties\PublishProfiles\**\*" />
 
      <FilesForPackagingFromProject  Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>


Exclude From Deployment
<PropertyGroup>
    <ExcludeFilesFromPackageDependsOn>
        $(ExcludeFilesFromPackageDependsOn);
        _ExcludeAzureDlls
    </ExcludeFilesFromPackageDependsOn>
</PropertyGroup>

<Target Name="_ExcludeAzureDlls">
    <ItemGroup>
        <AzureFiles Include="@(FilesForPackagingFromProject)"
                    Exclude="@(FilesForPackagingFromProjectWithNoAzure)" />
        <ExcludeFromPackageFiles Include="@(AzureFiles)">
            <FromTarget>_ExcludeAzureEnvironmentDlls</FromTarget>
        </ExcludeFromPackageFiles>
    </ItemGroup>
</Target>

 
here is a MSDN FAQ about Web Deployment http://msdn.microsoft.com/en-us/library/ee942158.aspx it also helped abit

Web Deployement in TFS2012

Web Deployment in VS2012 relies on the new Publish framework and the use of publish profiles.
using these profile gives us the ability to create different publishing for different environments.

all that is nice and well and work splendid with the VS2012, but what with my Builds?

We have 2 options:
  1. Add to Build Definition, Process->Advanced->MSBuild Arguments "/p:DeployOnBuild=true /p:PublishProfile=<Publish Profile Name>"
  2. Add the following lines to a project configuration
<DeployOnBuild>True</DeployOnBuild>
<PublishProfile>Deploy2</PublishProfile>

Using option 2 works better with multiple websites in the same solution

Also for File System Publish update publish profile like this, because of a bug in the build:
<publishUrl>$(MSBuildThisFileDirectory)..\Deployment\</publishUrl>


$(MSBuildThisFileDirectory) - the location of the pubxml in the project properties

Shutdown TFS

The TFS contains many web services and some windows services.
You can use the TFSServiceControl command to stop or start all of the services and application pools Visual Studio Team Foundation Server uses. For example, you use this command when backing up or restoring databases, or when you are moving your deployment from one machine to another.

TFSServiceControl [quiesce|unquiesce]

Option
Description
quiesce
Stops or pauses all of the services, application pools, and operations in your deployment of Team Foundation Server. This is required for certain maintenance tasks, such as restoring databases.
unquiesce
Starts or restarts all of the services, application pools, and operations in your deployment of Team Foundation Server. This is required to return your server to operation after you run the command with the quiesce option.

TFPT Command Line Install

the TFS power tools are a strong and helpfull extenstion.
they only have one problem, they contain the Process Template Editor.
it's true that permission issues prevent you from performing mistakes.
but in every organization there are some people who have the permission and tempering with the process template is not somthing they should do.

i have looked around and could not find any documaentation about silent install with selected featues
so i look in the MSI  (InstEd) and using the Msiexec paramters, I managed to create a silent intall batch that enables you to select the features.

Features you can use:
FeatureDescription
CHECKINPOLICIESCheckin policies
TSXIntegration with Windows Shell
TSX_64Integration with Windows Shell for 64bit OS
CLICommand line Application (tfpt.exe)
VSIPIntegration with Visual Studio (Find, Rollback, ...)
TFPSPowerShell Scripts
PROCESSEDITORProcess Template Editor
BPABest Practices Analyzer
TCMACTest Attachment Cleaner
BRDatabase Backup Tools
TFSTORYBOARDStoryboard Shapes Authoring Tool (TFS2012 only)

Ex. install only checkin policies, windows shell integration, command line and Visual Studio integration
msiexec /quiet /i tfpt.msi ADDDEFAULT=CHECKINPOLICIES,TSX,CLI,VSIP

Various TFS Cache Directories

Visual Studio / TFS Cache

Windows XP, 2003
C:\Documents and Settings\[USER]\Local Settings\Application Data\Microsoft\Team Foundation\

Windows 7,2008,....
C:\users\[user]\AppData\Local\Microsoft\Team Foundation\

Test Agents
Windows XP, 2003
C:\Documents and Settings\[Agent Service User]\Local Settings\Application Data\VSEQT\QTAgent

Windows 7 ,2008 ,...
C:\Users\[Agent Service User]\AppData\Local\VSEQT\QTAgent

TFS Build Agents

Windows XP, 2003
C:\Documents and Settings\[Build Service User]\Local Settings\Temp\BuildAgent\[Agent ID]
C:\Documentsand Settings\[Build Service User]\Local Settings\Temp\BuildController\[Controller ID]

Windows 7,2008,....
C:\Users\[Build Service User]\AppData\Local\Temp\BuildAgent
C:\Users\[Build Service User]\AppData\Local\Temp\BuildController

 

Friday, March 22, 2013

How To: Keep Test Items Deployment Structure

when using deployment items in tests we sometimes need to keep the stucture of test items as it appers in our local machine. by default the all the deployment items are copied to the same folder regardless the source location structure.

we can set the target destination by editing the "TestSettings" XML
all we need to do is update the DeploymentItem with outputDirectory attribute
 
here is an example for a folder:
<DeploymentItem filename="CoreSettings\" outputDirectory="CoreSettings\">

a small word of caution updating the XML will not show in the desginer until you reload the solution.


found at : http://stackoverflow.com/questions/10162436/visual-studio-2010-does-not-copy-folder-on-deployment-to-out-directory

Private accessors and TFS2012 Builds


sometimes old test containing privert accessors will fail the build with Error:
 
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamTest\Microsoft.TeamTest.targets (14): Object reference not set to an instance of an object.

 

first try to remove the private accessors and use a mocking framework (pex/moles or VS2012 Fakes)
But if due to any reason, you cannot remove the usage of private accessors immediately from your tests, please try changing the TeamTest targets file ("C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamTest\Microsoft.TeamTest.targets") and see whether running the shadow task in a separate process works or not.

Here are the steps you should do for this: -

  1. Edit the targets file ‘C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamTest\Microsoft.TeamTest.targets’.

  1. Change ExecuteAsTool property (highlighted) from default false to true.

<Target Name="ResolveTestReferences" Condition="'@(Shadow)'!=''">
  <BuildShadowTask
      ExecuteAsTool="True"  <!—Default value is false, change it to true –>
      CurrentResolvedReferences="@(ReferencePath)"
      CurrentCopyLocalFiles="@(ReferenceCopyLocalPaths)"
      Shadows="@(Shadow)"
      ProjectPath="$(ProjectDir)"
      IntermediatePath="$(IntermediateOutputPath)"
      SignAssembly="$(SignAssembly)"
      KeyFile="$(AssemblyOriginatorKeyFile)"
      DelaySign="$(DelaySign)">
 
    <Output TaskParameter="FixedUpReferences" ItemName="ReferencePath"/>
    <Output TaskParameter="NewCopyLocalAssemblies" ItemName="ReferenceCopyLocalPaths"/>
  </BuildShadowTask>
</Target>

  1. Save the file. (and probably restart the machine as well so that the background msbuild processes definitely picks up the change)

 




RoboCopy Exit Codes

During my work at Capito ,i came to a client were wanted a Build-Deploy-Test using Lab build.
the build part worked well but we had a small problem with the deployment scripts.
we were using RoboCopy in the deployment scripts. apparently the return code are very different:


The return code from Robocopy is a bit map, defined as follows:


Hex
Decimal 
Meaning if set
0×10
16
Serious error. Robocopy did not copy any files.
Either a usage error or an error due to insufficient access privileges on the source or destination directories.
0×08
8
Some files or directories could not be copied
(copy errors occurred and the retry limit was exceeded).
Check these errors further.
0×04
4
Some Mismatched files or directories were detected.
Examine the output log. Some housekeeping may be needed.
0×02
2
Some Extra files or directories were detected.
Examine the output log for details.
0×01
1
One or more files were copied successfully (that is, new files have arrived).
0×00
0
No errors occurred, and no copying was done.
The source and destination directory trees are completely synchronized.

You can use this in a batch file to report anomalies, as follows:

    if errorlevel 16 echo ***FATAL ERROR*** & goto end
    if errorlevel 15 echo OKCOPY + FAIL + MISMATCHES + XTRA & goto end
    if errorlevel 14 echo FAIL + MISMATCHES + XTRA & goto end
    if errorlevel 13 echo OKCOPY + FAIL + MISMATCHES & goto end
    if errorlevel 12 echo FAIL + MISMATCHES& goto end
    if errorlevel 11 echo OKCOPY + FAIL + XTRA & goto end
    if errorlevel 10 echo FAIL + XTRA & goto end
    if errorlevel 9 echo OKCOPY + FAIL & goto end
    if errorlevel 8 echo FAIL & goto end
    if errorlevel 7 echo OKCOPY + MISMATCHES + XTRA & goto end
    if errorlevel 6 echo MISMATCHES + XTRA & goto end
    if errorlevel 5 echo OKCOPY + MISMATCHES & goto end
    if errorlevel 4 echo MISMATCHES & goto end
    if errorlevel 3 echo OKCOPY + XTRA & goto end
    if errorlevel 2 echo XTRA & goto end
    if errorlevel 1 echo OKCOPY & goto end
    if errorlevel 0 echo No Change & goto end

i found this at http://ss64.com/nt/robocopy-exit.html

Welcom

Hello everyone

this is my first post in this blog.
this blog is all about my (Liran Dobrish) finding about various subjects with TFS.
and related subjects