Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

"Add as Link" missing from Visual Studio #147

Closed
Daniel15 opened this issue Aug 15, 2015 · 29 comments
Closed

"Add as Link" missing from Visual Studio #147

Daniel15 opened this issue Aug 15, 2015 · 29 comments

Comments

@Daniel15
Copy link

Classic project types (eg. ASP.NET 4, Console Application, Class Library) have an "Add as Link" option in the "Add Existing Item" dialog. This allows one file to be shared across multiple projects, by adding the file to the project without physically copying the file to the project directory. This button is missing from the Add Existing Item dialog for ASP.NET 5 projects.

It appears you can achieve something similar through the shared section in project.json. However, files added this way do not appear under the project in Solution Explorer.

@sayedihashimi
Copy link
Contributor

@Daniel15 thanks for the note, we have it on our backlog but have not started on it yet. I'll reply here when we do.

@sayedihashimi
Copy link
Contributor

TFS:121783

@joplaal
Copy link

joplaal commented Nov 11, 2015

Some scenarios are covered with the solution stated in aspnet/dnx#550 (using "shared files" in project.json (https://github.com/aspnet/Home/wiki/Project.json-file#shared-files)

But when you need to have the same file on several projects, that it's not a compilable one, that does not work.

A common usage would be to have a shared config.json file shared between several projects on the same solution. ¿Is there any way to achieve that without linked files?

@Daniel15
Copy link
Author

@davidfowl - Do files added like that appear in Solution Explorer? Can I add them via the "Add as Link" option in the UI? Not seeing the files in the solution explorer is a pretty big issue - How am I meant to know exactly which files are being included via the compile attribute? Manually looking in Windows Explorer isn't really an appropriate solution for something an IDE should handle 😄

@sayedihashimi
Copy link
Contributor

We don't show those files today but we are planning on adding support to show them.

@niemyjski
Copy link

Any ETA on this? I get that I can do it today but it's kind of black magic without seeing this file in solution explorer.

@ToddThomson
Copy link

What if I want to share non cs file resources? While in active development, it is simple to add existing common js and less files as links and then have any modification within a project update the original source. The only alternative is to use a client-side package manager like bower, but while in active development this is too time consuming.
Please let us keep the csproj add files as links within visual studio.

@jordimontana82
Copy link

Is the shared files approach still supported? Links were removed or moved to a different place, getting 404s.

Would be nice to have the ability to add files as links tho.

@rpaschoal
Copy link

+1

I just needed this feature to share some Angular2 components with another application and couldn't use it.

Any ETA on this?

Thanks!

@jimbuck
Copy link

jimbuck commented Jul 27, 2016

If you only need it for a file or two, a simple work-around is to edit your xproj with the same XML generated within a csproj. For example:

<ItemGroup>
    <Content Include="..\..\Some\Common\Project\file-to-be-shared.json">
      <Link>linked-copy.json</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content> 
</ItemGroup>

The only downside is that it does not work when using the dotnet CLI tools, just Visual Studio.

@simplexidev
Copy link

Is there a simpler way to workaround this issue other than manually adding each one to the xproj? This isn't exactly the best workaround for multiple files.

@jimbuck
Copy link

jimbuck commented Aug 1, 2016

@tom-corwin It's hacky, I know. I'd create a powershell script or two depending on your use case.

If it's the same file (or few files) that must get copied to many projects then just make a simple CLI script to batch update all project files.

The second script would just open a file picker and allow the user to select a file, then update the xproj accordingly (meant to be used during active development).

@jimbuck
Copy link

jimbuck commented Aug 1, 2016

I will try to throw one together later, but if you do make sure to post it here for everyone!

@simplexidev
Copy link

@JimmyBoh I will try to create one, but it will probably be a csproj since I'm not familiar with PowerScript at all 😜

@madhav5589
Copy link

@davidfowl The links that you provided isn't working. Can you please provide the updated link?
Thanks.

@manastalukdar
Copy link

Would appreciate the tooling allowing for adding files as links sooner rather than later. I am having to manually add in linked files by editing the xproj which isn't very productive.

@mvadu
Copy link

mvadu commented Oct 5, 2016

Any ETA on this one? Its open for more than a year with two updates to Visual Studio 2015 in the mean time. I am trying to share same source across .Net Core (1.0) and classic 4.5, and this is a dead end.

@Daniel15
Copy link
Author

Daniel15 commented Oct 5, 2016

I am trying to share same source across .Net Core (1.0) and classic 4.5,

@mvadu - I've found the least error-prone way of doing that is to move the code into the .NET Core project, and "Add as Link" from the classic 4.5 project. This will make it appear in both projects in the solution explorer.

If you need any conditional bits of code, you can use preprocessor directives.

@pgmolloy
Copy link

pgmolloy commented Oct 5, 2016

Just adding support for the "Add as link" in Visual Studio. Huge efficiency gains to be created in agile development and multi-refactoring where shared source can be tested across development instances.

Is there a specific MS developer VS feature statistical report on how many developers rank which feature requests at what importance level. GitHub would be a good place to show this metric providing some real time visibility to what is important across the tooling environment.

@sayedihashimi
Copy link
Contributor

Support for this will becoming in the next release when we move to .csproj.

@CodingSamurai
Copy link

+1 for needing this functionality. Makes a huge difference in ensuring no code duplication is necessary.

@riiight
Copy link

riiight commented Jan 4, 2017

Chiming in to add my vote for this feature.

@sayedihashimi
Copy link
Contributor

Linked files are supported in the latest version of VS2017 RC. @riiight have you tried with VS2017 RC and had issues?

@ghost
Copy link

ghost commented Jan 24, 2017

vs2015 update 3 ..
Hold ALT key and Drag&Drop your file. (you ll see little shortcut icon on the mouse)

@davidfowl
Copy link
Member

This will be fixed with the new csproj tooling in VS 2017

@zwcloud
Copy link

zwcloud commented Mar 30, 2017

Is there a way to add multiple directories/files as links at once?
@705am Hold ALT key and Drag&Drop doesn't work in VS2017. The dragged files get copied instead of linked.

@sankar1204
Copy link

sankar1204 commented Apr 17, 2017

Based on @JimmyBoh 's idea, I added below lines to .xproj,
(for me, it was to add a shared AssemblyInfo.cs file to project properties)

<ItemGroup>
    <Compile Include="..\..\AssemblyInfo.cs">
      <Link>Properties\AssemblyInfo.cs</Link>
    </Compile>
</ItemGroup>

It worked and I could also see linked file in SolutionExplorer.

@prisar
Copy link

prisar commented May 9, 2018

I also wanted to know this. Thanks, this issue helped me

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests