asp.net core and including shared content files

梦想的初衷 提交于 2019-12-10 16:02:00

问题


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

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.

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?

Thanks

Donal


回答1:


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.

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 has a similar (but less commonly used) feature:

> mklink /J common ..\Common.Includes

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

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

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'.

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

Then reference it from "scripts":

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


来源:https://stackoverflow.com/questions/38509871/asp-net-core-and-including-shared-content-files

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