Elton Stoneman

  Home  |   Contact  |   Syndication    |   Login
  120 Posts | 0 Stories | 3607 Comments | 0 Trackbacks

News

Archives

Post Categories

[Source: http://geekswithblogs.net/EltonStoneman]

Windows shortcuts are .LNK files – a proprietary binary format which is not simple to generate. If you want to create shortcuts as part of an MSBuild deployment, the main issue is that the paths are not relative, they need to be explicit, so you can't create your own shortcuts and copy them. Alternatives are to create .URL or batch files containing relative paths, but they don't have the niceties of shortcuts.

You can generate .LNK shortcuts in MSBuild by shelling out to some VBScript at runtime, when you've deployed your files and know the exact paths. It's not a pretty solution, but it's fast and reliable. Create a .VBS file with the following content to generate a shortcut from given parameters:

'CreateShortcut.vbs

'Generates a .LNK shortcut to the specified program

'Usage: CreateShortcut.vbs <pathToExe> <exeName> <shortcutName>

 

Dim args, arg

Set args = WScript.Arguments

 

Dim workingDirectory, exeName, shortcutName

workingDirectory=args(0)

exeName=args(1)

shortcutName=args(2)

 

Dim WshShell

Set WshShell = WScript.CreateObject("WScript.Shell")

 

Dim objLink

Set objLink = WshShell.CreateShortcut("Shortcuts\" & shortcutName & ".lnk")

objLink.Description = shortcutName

objLink.TargetPath = workingDirectory & "\" & exeName

objLink.WindowStyle = 1

objLink.WorkingDirectory = workingDirectory

objLink.Save

Then call it from MSBuild after you've deployed the target file and know the path:

<Exec Command='CreateShortcut.vbs """$(AppDir)""" AppName.exe AppFriendlyName.exe'/>

Points to note:

  • If you have any spaces in the arguments (C:\Program Files\etc) you need to wrap them in triple double-quotes ("""C:\Program Files\etc"""), otherwise each word is parsed as a separate argument in VBScript;
  • The friendly name of the shortcut can end in any extension – Windows hides the final .LNK , so if you specify a .EXE it will display as an EXE;
  • Shortcuts aren't limited to executables, if you pass a Word file as the exeName argument and end the shortcutName with .DOC, it'll launch the document in Word and show it with the Word icon in Explorer;
  • You have a lot of control over the link from the CreateShortcut call – including the startup window type, arguments and the icon. The example above is a straightforward one which just sets the minimum necessary.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Friday, October 24, 2008 7:13 PM

Feedback

# re: Creating Shortcuts in MSBuild 8/26/2009 4:39 AM typy bukmacherskie
Wow, great answer to fix my bug, i've got space in my arguments and i did not understand why did it bug ? That post makes me realize my mistake, thx for that helpful resource !

# re: Creating Shortcuts in MSBuild 10/19/2010 7:41 AM seo experts
If you want to create shortcuts as part of an MSBuild deployment, the main issue is that the paths are not relative, they need to be explicit, so you can't create your own shortcuts and copy them.Thanks.

# re: Creating Shortcuts in MSBuild 11/3/2010 2:27 AM ultrasound technician schools
I have searched in the internet to find an easy way to rebuild my visual studio solution without open it. Then I find there is a way to update the registry to provide a context shortcut to run msbuild command by right-click on .sln file from.

# re: Creating Shortcuts in MSBuild 11/9/2010 8:38 AM digital scrapbook
During the course of development, it's important to have an automated build process. Equally important is having an automated means of creating releases.

# re: Creating Shortcuts in MSBuild 12/8/2010 2:57 AM Digital Scrapbooking
MSBuild is the build system for Visual Studio. The MSBuild project file format enables developers to fully describe what items need to be built. It is a significant progress for Visual Studio. I am searching an easy way to rebuild my visual studio solution without open it. I searched in the internet, and then I got a way to update the registry to provide a context shortcut to run msbuild command by right-click on .sln file.

# re: Creating Shortcuts in MSBuild 3/3/2011 5:33 AM driving lessons in Milton Keynes
The .NET 2 platform is delivered with a new tool named msbuild.exe. This tool is used to build .NET applications. It accepts XML files which describe the sequence of tasks for the build process. Thank you for the information about creating the shortcut of msbuild. This is exactly what I was looking for.

# re: Creating Shortcuts in MSBuild 3/9/2011 11:08 AM Fly Ash Transportation
Thanks for this post.I would like to read more about your articles.That contains nice information....Thanks.


# re: Creating Shortcuts in MSBuild 3/26/2011 3:50 AM article submission services
MSBuild is a significant progress for Visual Studio. I am searching an easy way to rebuild my visual studio solution without open it. Hope your tips will be helpful for me.

# re: Creating Shortcuts in MSBuild 5/13/2011 7:23 AM law degree online
Absolutely, shortcuts cannot use relative address as this can makes user confused when use the shortcut.

# re: Creating Shortcuts in MSBuild 7/15/2011 6:17 AM Solidworks
You gave tremendous positive points there. I did a search on the topic and found most peoples will agree with your blog.


# re: Creating Shortcuts in MSBuild 7/28/2011 6:02 AM Heathrow Taxi
MSBuild is the build system for Visual Studio. The MSBuild project file format enables developers to fully describe what items need to be built. It accepts XML files which describe the sequence of tasks for the build process.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: