ASP.NET Core 发布排除文件夹(或 .json 文件)

编程入门 行业动态 更新时间:2024-10-20 00:33:29
本文介绍了ASP.NET Core 发布排除文件夹(或 .json 文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 asp 核心 2.1 项目,我正在尝试通过网络部署发布.

I have an asp core 2.1 project, and I'm trying to publish via web deploy.

我有一个名为Angular"的文件夹,里面有我的源文件(包括一些用于 angular 配置的 .json 文件)——这些文件被构建(通过一个单独的进程ng build")到 wwwroot/app 目录中,准备好发布.因此,我不希望此 Angular 目录中的任何内容都出现在已发布的文件夹中.但我仍然希望 Angular 文件夹显示在项目/解决方案资源管理器/在文件中查找.

I have a folder called "Angular" and inside that are my source files (including some .json files for angular's config) - these get built (via a separate process "ng build") into the wwwroot/app directory ready for publish. As such, I want NOTHING from this Angular directory to end up on the published folder. But I still want the Angular folder to show up in the project / solution explorer / find in files.

目前正在发布包含所有 .json 文件的 Angular 文件夹.显然这很糟糕,我需要阻止这种情况发生.我很确定这是因为这个......github/aspnet/websdk/blob/dev/src/ProjectSystem/Microsoft.NET.Sdk.Web.ProjectSystem.Targets/netstandard1.0/Microsoft.NET.Sdk.Web.ProjectSystem.props#L32

At present, it is publishing the Angular folder with all .json files inside. Obviously this is bad and I need to stop this from happening. I'm pretty sure this is happening because of this... github/aspnet/websdk/blob/dev/src/ProjectSystem/Microsoft.NET.Sdk.Web.ProjectSystem.Targets/netstandard1.0/Microsoft.NET.Sdk.Web.ProjectSystem.props#L32

我使用以下命令发布:

dotnet publish C:\blah\ -c Release /p:PublishProfile=WebDeployProfile

(有时也使用相同的配置文件通过 Visual Studio Publish 执行此操作,但频率较低 - 我注意到这些功能不同,我觉得很奇怪)

(and also sometimes doing it via the Visual Studio Publish using the same profile, but less frequently - I notice that these function differently, which I find odd)

我在 .csproj 和 .pubxml 中尝试了很多不同的东西,这变得很荒谬,而且我目前认为 msbuild/deploy 一团糟,而且很糟糕.

I have tried so many different things, both in the .csproj and .pubxml, it's getting ridiculous, and I currently believe msbuild/deploy is a total mess, and quite broken.

我希望有人能帮助我完成一件极其简单易行的事情——从发布中排除一个文件夹(同时将它留在项目中).

I am hoping someone can help me with what should be a supremely simple and easy thing to accomplish - exclude a folder from publish (whilst leaving it in the project).

推荐答案

我遇到了同样的问题.

我有一个文件夹,其中包含多个 json 文件,发布过程将这些文件提取并发送到发布输出.

I had a folder that included multiple json files that the publish process picked up and sent to the publish output.

要排除诸如FolderYouDontWant"之类的文件夹,请将以下内容添加到您的 .csproj 文件中:

For excluding a folder such as 'FolderYouDontWant' add the following to your .csproj file:

<ItemGroup> <Content Update="FolderYouDontWant\**\*.*" CopyToPublishDirectory="Never" /> </ItemGroup>

如果您要排除特定文件而不是整个文件夹,请使用确切的文件路径,例如:

If you have specific files you are looking for to exclude rather than whole folders, use the exact file path such as:

<ItemGroup> <Content Update="FolderWithFile\dont-want.json" CopyToPublishDirectory="Never" /> </ItemGroup>

如果您有多个路径,您可以将所有内容元素添加到同一个ItemGroup.

If you have multiple paths you can add all of the Content elements to the same ItemGroup.

更多推荐

ASP.NET Core 发布排除文件夹(或 .json 文件)

本文发布于:2023-11-07 11:00:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566272.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   文件   NET   ASP   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!