How do you add a file as a link in a .NET Core lib

2019-04-18 23:28发布

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?

2条回答
闹够了就滚
2楼-- · 2019-04-18 23:47

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"
            ]
         }
     }
}
查看更多
贼婆χ
3楼-- · 2019-04-18 23:53

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.

查看更多
登录 后发表回答