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

喜你入骨 提交于 2019-12-10 00:58:31

问题


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?


回答1:


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"
            ]
         }
     }
}



回答2:


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.



来源:https://stackoverflow.com/questions/37333368/how-do-you-add-a-file-as-a-link-in-a-net-core-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!