导读 本文介绍的是在使用nuget打包的过程中遇到丢失文件的问题的时候使用powershell脚本实现的解决办法,非常的巧妙

对于进行nuget打包时,有时我们需要添加一个配置文件,就是一些文本文件,而这些文件我们在网站发布时需要同时复制到输出目录,否则会出现文件丢失的问题,我们在打包时通过添加powershell脚本来解决它。

一般添加powershell包之后,包的格式如下

添加-〉工具-〉install.ps1脚本

param($installPath, $toolsPath, $package, $project)
$configItem = $project.ProjectItems.Item("log4.config")
 
# set 'Copy To Output Directory' to 'Copy if newer'
$copyToOutput = $configItem.Properties.Item("CopyToOutputDirectory")
$copyToOutput.Value = 1
 
# set 'Build Action' to 'Content'
$buildAction = $configItem.Properties.Item("BuildAction")
$buildAction.Value = 2

当我们在项目里添加nuget包时,查看输出窗口,可以看到我们的ps1脚本被自动执行了,它修改了log4.config的文件属性,它让具有“始终复制”到输出目录的属性!

现在我们在建立nuget包时,如果希望进行一些初始化的功能,就可以使用这种方式了!

原文来自:https://www.jb51.net/article/127639.htm

本文地址:https://www.linuxprobe.com/powershell-nuget.html编辑:向云艳,审核员:逄增宝

Linux命令大全:https://www.linuxcool.com/

Linux系统大全:https://www.linuxdown.com/

红帽认证RHCE考试心得:https://www.rhce.net/