How do you add a file as a link in a .NET Core library?
Asked Answered
S

2

17

I've added a .NET Core RC2 class lib to my solution (for fun) and the first thing I usually do is add a link to a shared GlobalAssemblyInfo.cs and edit the existing AssemblyInfo.cs down to the assembly specifics.

So I've just done "Add"->"existing item", located my file and clicked the dropdown of the add button. No "Add as Link" option.

What's the deal? How do I do this with .NET Core?

Showpiece answered 19/5, 2016 at 20:26 Comment(1)
See discussion github.com/aspnet/Tooling/issues/147Hellcat
R
9

I don’t think the tooling supports this yet, and unfortunately, the documentation is not up to date on this yet.

However, you can get an idea on how this works from this ASP.NET Core announcement. Basically, you can add individual file paths to the buildOptions.compile.includeFiles setting in your project.json:

{
    "buildOptions": {
        // …
        "compile": {
            // …
            "includeFiles": [
                // …
                "../shared/GlobalAssemblyInfo.cs"
            ]
         }
     }
}
Rosewater answered 19/5, 2016 at 20:31 Comment(1)
The current tooling is only a first preview, and they are still working on that before RTM. Although, I don’t expect that many changes considering that they announced to partly go back to .csproj files again, so the existing tooling will probably end up covering that eventually.Rosewater
H
5

Copy of JimmyBoh comment on Jul 28, 2016 on https://github.com/aspnet/Tooling/issues/147:

For non-compilable files 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.

Hellcat answered 3/2, 2017 at 12:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.