nuget 覆盖文件 [英] nuget overwrite files

查看:76
本文介绍了nuget 覆盖文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以强制 nuGet 包覆盖现有文件?我需要一种在 3 个类似项目中应用补丁(文件、dll、资源)的好方法,通过它这可能是一个很好的解决方案.

Is it possible to force nuGet packages to overwrite existing files? I need a nice way of applying patches (files, dll, resources) across 3 similar projects and through that this could be a nice solution.

推荐答案

可以通过 powershell 和包依赖来完成...

It can be accomplished with powershell and a package dependencies...

我有一个为 ASP.NET MVC 创建的 NuGet 包,它包含我想要添加到标准 Mvc 项目的所有文件(DisplayTemplates、EditorTemplate、Extensions、BaseController 等).假设它叫做Company.WebMvc"

I have a NuGet package that I create for ASP.NET MVC it has all the files that I want to add to the standard Mvc project (DisplayTemplates, EditorTemplate, Extensions, BaseController, etc). Let say its called "Company.WebMvc"

我创建了另一个名为Company.WebMvc-Prep"的 NuGet 包,它有一个 Install.ps1 脚本,可以从标准 Mvc 项目中删除我不想要的任何内容.这是删除现有脚本文件的代码示例...

I created another NuGet package called "Company.WebMvc-Prep" That has an Install.ps1 script that deletes anything I don't want from the standard Mvc project. Here is an code example of deleting the existing Scripts files...

param($installPath, $toolsPath, $package, $project)

#Remove Script Files

$scripts = $project.ProjectItems | Where-Object { $_.Name -eq "Scripts" }

if ($scripts) {

    $scripts.ProjectItems | ForEach-Object { $_.Delete() }

}

然后我使Company.WebMvc-Prep"成为Company.WebMvc"的依赖项.为什么?因为 Install.ps1(通常)在 NuGet 添加内容文件夹中的文件后运行.我需要它先删除文件,然后添加新文件.所以当你打电话...

I then make "Company.WebMvc-Prep" a dependency of "Company.WebMvc". Why? because Install.ps1 (normally) is run after NuGet adds the files from the content folder. I need it to delete the files first then add the new ones. So when you call...

安装包 Company.WebMvc

Install-Package Company.WebMvc

首先安装Company.WebMvc-Prep,因为它是一个依赖项(运行Install.ps1)

Company.WebMvc-Prep is installed first because it is a dependency (runs Install.ps1)

然后安装 Company.WebMvc 以添加您的内容.

Then Company.WebMvc is installed which adds your content.

总而言之……您可以通过 NuGet 包覆盖项目中的现有内容.

Long and short of it is... You Can overwrite existing content on your project via a NuGet package.

附言请记住,您也可以使用部分类来隔离 NuGet 包代码与项目特定代码.

P.S. Remember you can also you partial classes to isolate NuGet package code vs. project specific code.

这篇关于nuget 覆盖文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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