如何在 .NET Core 库中将文件添加为 link?

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

我已将 .NET Core RC2 class 库添加到我的解决方案中(为了好玩),我通常做的第一件事是将 link 添加到共享 GlobalAssemblyInfo.cs并将现有的 AssemblyInfo.cs 编辑为装配细节。

所以我刚刚完成 "Add"->"existing item",找到我的文件并单击添加按钮的下拉菜单。没有 "Add as Link" 选项。

怎么回事?我如何使用 .NET Core 执行此操作?

我认为工具还不支持这一点,不幸的是,文档还不是最新的。

不过,您可以从 ASP.NET Core announcement 中了解其工作原理。基本上,您可以将单个文件路径添加到 project.json:

中的 buildOptions.compile.includeFiles 设置
{
    "buildOptions": {
        // …
        "compile": {
            // …
            "includeFiles": [
                // …
                "../shared/GlobalAssemblyInfo.cs"
            ]
         }
     }
}

JimmyBoh 2016 年 7 月 28 日在 https://github.com/aspnet/Tooling/issues/147 上的评论副本:

对于 non-compilable 文件,一个简单的 work-around 是使用在 csproj 中生成的相同 XML 编辑您的 xproj。例如:

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

唯一的缺点是它在使用 dotnet CLI 工具时不起作用,只是 Visual Studio。