2

First, sorry for my English.. How can I include an existing shortcut into my solution?

When I try to add an existing item into my project, the visual studio seems to try to add the link destination, not the link itself, because it give me the following error:

Cannot find file "C:\linkdestination.exe"

But the link works fine.

Anyone knows how to do this?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Guilherme
  • 5,143
  • 5
  • 39
  • 60
  • 1
    Why do you want to? It's much easier to generate the link on the system where the app runs when required - also, what if someone has installed the application in question in a different location? Eg `D:\Program Files\` or similar? – Basic Feb 17 '13 at 22:10
  • I'm making a personal installer for my application, and the install path is fixed. Also, I have searched how I can generate a shortcut into C#, but the best way to do this is using a third part class: http://stackoverflow.com/questions/234231/creating-application-shortcut-in-a-directory – Guilherme Feb 17 '13 at 22:16
  • Next question then... Are you using an installer project? If so, [it can auto-generate a link for you](http://stackoverflow.com/a/6886973/156755) or failing that, you can add it as a resource for your C# project. That will include it as a static, uninterpreted file [which you can access using a bit of reflection](http://support.microsoft.com/kb/319292) – Basic Feb 17 '13 at 22:25
  • Also note that you can generate one without too much effort (~10 lines) in C# with no external libraries... http://stackoverflow.com/a/4897700/156755 – Basic Feb 17 '13 at 22:31
  • Ok, thanks to your answers. I'm not using a install project, I started from blank solution. The installer is working fine, the only problem that I've found is how to put a shortcut into desktop after installation. I will try to generate the shortcut with the methods of this post (stackoverflow.com/a/4897700/156755) and post here the results. – Guilherme Feb 17 '13 at 22:42
  • 1
    If it's just for you ti doesn't matter but you should know that writing a robust installer is non-trivial. There are a lot of things to consider (like versioning of DLLs, Prerequisites (eg .Net Framework) and uninstalling everything that's no longer needed by your app but nothing used by others, etc.). If you want to write an installer for use in the wild, you should definitely use an installer project (or an alternative like the [Nullsoft Scriptable Install System](http://nsis.sourceforge.net/Main_Page)) – Basic Feb 17 '13 at 23:10

1 Answers1

2

I had to do that (added lnk to PS script).

Simply rename your lnk to sth else, for example TXT.

REN "Foo.lnk" "Foo.txt"

Then add it to your solution in VS. When done, rename it in VS back to .lnk extension.

emdee.pro
  • 143
  • 9
  • This works for what I need: "Avoiding MSI self-fix with regular shortcuts" – MetalGeorge Feb 09 '16 at 02:07
  • The key bit here for me was to use the quote `REN` command in a command window, rather than trying to use Windows Explorer, as WE still keeps the `.lnk` file suffix and VS will not then include it. – Dib Jul 14 '17 at 08:37