How to export C# project with linked files (Files Added with "Add Existing Item" and "Add as link")?
Category: visual studio extensibility
Yasemni YÜKSEL on Fri, 25 Mar 2016 09:51:31
I want to create Project template and to use it while creating new projects. I have a problem. The problem is : My template Project contains linked files (Linked files means added with "Add existing item" and "Add as link"). But If I create a new project from this template my linked files' Full Path is being incorrect. Why? How can i solve this problem?
Esat Özdemir on Fri, 25 Mar 2016 11:30:13
Şuan Türkiye forumundasınız , sorununuzu Türkçe olarak anlatırsanız size daha kolay yardımcı olmamızı sağlayabilirsiniz.
Yasemni YÜKSEL on Fri, 25 Mar 2016 14:30:01
Visual Studio 2012'de yeni proje oluştururken kullanmak üzere Proje Şablonu (Template'i) oluşturuyorum (File --> Export Template diyerek). Şablon projemde Add --> Existing Item --> Add As Link ile eklenmiş dosyalar (yani classlar) varsa onların dosya yolunu değiştiriyor. Aslında Benim D:\Folder1\Folder2\ şeklinde olması gereken dosya yolum C:\Users\YASEMIN\AppData\Local\Temp\Folder2 şeklinde geliyor.
Bu hata Add As Link ile projeye eklediğim classlar için oluşuyor? Çözümünü bilen varsa yardımcı olursa sevinirim.
CoolDadTx on Fri, 25 Mar 2016 15:26:30
A project template is used to generate a single project. The purpose of a linked file is to allow you to share a file across projects. Since a project template encapsulates a single project it isn't going to work. I can add your project to an empty solution and thus all your links would be invalid.
VS does support the concept of multi-project templates. You would need to implement that type of template before linked files would even make sense. But even in that case the linked files really need to reside in one of the projects and linked by the other project. This should solve the pathing issue.
If you really need to have the file on an arbitrary path then project templates no longer make sense. A project template isn't supposed to require anything outside the project itself and NuGet dependencies. You can do it but you're probably going to have to use a full VS package.
Linked files are of limited usefulness in most apps these days except when you're trying to build different variants of the same code base (i.e. .NET Core, .NET Full, Silverlight, etc). Unless that is your scenario a better approach would be to move the shared code into a separate project that can be built and put into NuGet. You can then add a NuGet dependency in each of your project templates.