Surendra Sharma

Surendra Sharma

Search This Blog

Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Friday, March 24, 2017

Sitecore Habitat : what to do if 05-Sync-Unicorn is not working



I have just started to play with Sitecore Habitat project. The first problem that I encounter is Habitat setup.
 

Everything worked fine except task “05-Sync-Unicorn”. I waited for an hour to complete it but it seems to showing in progress status as 

Sync Unicorn
Sync Unicorn

I googled for the solution but didn’t find any suitable link which explained it properly. So I decided to write the article

Follow below steps if "05-Sync-Unicorn" is not working for you


  • Login to Sitecore desktop

  • Open http://yourinstance/unicorn.aspx
 
Unicorn Sync Page
Unicorn Sync Page



  • You can sync Sitecore items by clicking "Sync" button for each component one by one

  1. Syncing process updates items in Master, core, link database and in search indexes.
  2. It also sync roles, users
  3. Finally it published all synced items to web
Sync Progress
Sync Progress

  • Run "06-Deploy-Transforms" from Visual Studio

Deploy Transforms
Deploy Transforms
 
  •  Open your instance on browser and hurreyyy you will get your Habitat site

Habitat Home Page
Habitat Home Page
 

I hope you like this Sitecore trick. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this trick if it’s useful for you.

Thursday, January 12, 2017

How to publish a single file in Visual Studio



I just learn a new secret of Visual Studio.

There are almost 10 projects in my single solution in Visual Studio. Every time if I make the changes in any file I have to build and publish it again to verify the changes on browser. If some code file is there than it’s understood that we have to build the solution and publish it. 

However if some static file is there like HTML, ASPX, XML, JS, CSS etc., still I was build the whole project and publish it where no code changes are involved. Ultimately to test the page I have to reload my web application which take enough time.

But Visual Studio provide a nice feature of publishing only a single file. This feature is very useful if file is static like HTML, aspx, XML, JS, CSS, image etc. You can also publish the code file as well.

You can use any of the mentioned way to use this feature

  • Just right click on file in Solution Explorer and select "Publish <FileName>".

  • Shortcut command is "Alt+; Alt+P".


Publish File from Solution Explorer
Publish File from Solution Explorer



  • Project Menu -> "Publish <FileName>".


Publish File from Project Menu
Publish File from Project Menu

It publish the single file within a fraction of second and now if you reload the page it will load quickly in browser.

I hope you like this hidden secret of Visual Studio. Stay tuned for more articles.

Please leave your comments or share this tip if it’s useful for you.

Tuesday, October 25, 2016

ROBOCOPY : Auto Push static files to hosting environments



Developers are working on their development machine during website development phase. Once they are done with their file changes, they are going to publish those changes. 
They can do publishing at any time without any efforts. But if solutions have lots of projects then this process take times. 

Can we avoid and minimize this time and automate this process at least for static files like 
images, HTML, views, aspx, css, js etc.?

Answer is YES. We can automate this process to sync development static files folders with Published folders.

Even we can push development change static files to QA and staging environment folders which are across the network.

Sync
Sync


How to push the changes?

I am using a batch file with ROBOCOPY command in my development machine for this.

ROBOCOPY stand for robust file copy and this command allows you to copy files, directories, and even drives from one location to another.

Robocopy monitor the source folder and if any change happened in that folder like new file created, file deleted, updated etc. then Robocopy takes all the files and replace those files on destination folder.

Syntax : ROBOCOPY source destination [options]

Create a batch file in solution root folder and put below script 

@ECHO OFF

REM this batch file uses robocopy to monitor certain folders in the web projects for changes
REM and copies the changes to the web directory to save time when editing non compiled
REM files such as javascript CSS and cshtml

SET SITEROOT=C:\inetpub\wwwroot\SitecoreLessons\Website
SET SLNROOT=%~dp0
SET OPTS=/MIR /MON:1 /MOT:1 /NJS /NDL /NP /NS /NC

START ROBOCOPY "%SLNROOT%\SitecoreLessons\Assets" "%SITEROOT%\Assets" %OPTS%

REM You can put multiple Robocopy command here like

REM START ROBOCOPY "%SLNROOT%\SitecoreLessons\Views" "%SITEROOT%\Views" %OPTS%


@EXIT

Here is the description of this batch file for those who don’t have any knowledge of batch files

ECHO -> Used to print on output device
REM -> Used to write comment in batch file
SET -> Used for declaring the variable like SITEROOT variable is used to store my destination folder path.
%~dp0 -> Current directory path from where this batch file is running

I have defined “OPTS” variable which stores ROBOCOPY command options


Options
Description
MIR
MIRror a directory tree
MON:1
MONitor source. Run again when more than n changes seen.
MOT:1
MOnitor source. Run again in m minutes Time, if changed.
NJS
No Job Summary.
NDL
No Directory List - don't log directory names.
NP
No Progress - don't display percentage copied.
NS
No Size - don't log file sizes.
NC
No Class - don't log file classes.



You can get more option from http://www.computerhope.com/robocopy.htm

Double click on this batch file to start monitor our source “Assets” folder as

Batch File
Batch File


I have added “Assets\Images” folder in my VS projects and paste some image files in this folder. 

Note: - I have not build or publish my VS solution till now. 

But if I wait for 1 min. I got new all image files in my “C:\inetpub\wwwroot\SitecoreLessons\Website\Assets\Images” folder automatically.

Sync Images
Sync Images


Wowww. This is cool. Now I can write more Robocopy command in same batch file for copying Views, ASPX, HTML files etc.

I hope this pointer helps you to improve your productivity in your development environment.

Please leave your comments and share this trick with other developers.