asp.net核心,包括共享内容文件 [英] asp.net core and including shared content files

查看:47
本文介绍了asp.net核心,包括共享内容文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Shared Project项目,其中包含一些内容文件,例如JSON等.

I have a Shared Project project which contains some content files like JSON, etc.

我有许多ASP.Net核心项目,并且我想包含/共享其中一些JSON文件.VS中的链接到文件"选项非常简单,但在ASP.Net核心项目中不可用.

I have a number of ASP.Net core projects and I want to include/share some of these JSON files. Very simple with the "Link to File" option in VS but it's not available in ASP.Net core projects.

我尝试按以下方式使用buildOptions/copyToOutput,但这似乎不起作用,并且在构建过程中未记录任何错误或警告.

I've tried playing with the buildOptions/copyToOutput as follows but this does not seem to be working and no error or warning logged in the build process.

"copyToOutput": {
    "include": [ "../Common.Includes/mysettings*.json" ] }

有任何想法感激地接受了吗?

Any ideas gratefully accepted?

谢谢

Donal

推荐答案

copyToOutput 设置对我来说很好(至少在 dotnet 1.0.0-preview3-003171 中在Windows上).但是请注意, copyToOutput不是可传递的-如果文件是在中复制的,则意味着有效项目A ,它们不会被复制到引用项目A 项目B 中的输出.

The copyToOutput setting works fine for me (at least in dotnet 1.0.0-preview3-003171 on Windows). Note however that copyToOutput is not transitive - meaning tath if the files are copied in project A, they won't be copied to output in project B that references project A.

另一种方法是使用基础文件系统并创建指向共享文件或文件夹的符号链接.在Linux上是:

Another method is to use underlying file system and create a symbolic link to the shared file or folder. On Linux it would be:

> ln -s ../Common.Includes common

Windows具有类似(但不太常用)的功能:

Windows has a similar (but less commonly used) feature:

> mklink /J common ..\Common.Includes

然后您可以配置 dotnet 使其在特定事件上运行:

You can then configure dotnet to run it on a specific event:

"scripts": {
    "precompile": "cmd /C mklink /J common ..\\Common.Includes"
}

在RC1中,还发生了诸如'prepare''prerestore'之类的事件,它们更适合于此,但是现在.

In RC1 there were also events like 'prepare' or 'prerestore', which would be more suitable for this, but for now they're gone and dotnet only supports 'precompile' and 'postcompile'.

最好将此命令与一个逻辑一起放在一个单独的脚本中,以检查链接是否已存在.在Windows上,我将创建 init.ps1 Powershell脚本:

It will be even better to put this command into a separate script along with some logic to check if the link already exists. On windows, I would create init.ps1 Powershell script:

if (!(Test-Path "common")) {
    cmd /C mklink /J "common" "..\Common.Includes"
}

然后从脚本" 引用它:

"scripts": {
    "precompile": "init.ps1"
}

这篇关于asp.net核心,包括共享内容文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆