問題:用NUGET打包了一個asp.netcore的項目,試圖安裝到另外一個asp.netcore項目中,除了自動添加引用外,還但願自動釋放一些文件以供修改。這些操做之前在netframe中是正常的,腳本以下 html
<?xml version="1.0"?> git
<package> github
<metadata> web
<id>Q.AspNetCore.Tpl</id> shell
<version>1.0.7</version> asp.net
<title>Q.AspNetCore.Tpl</title> post
<authors>Zhangwenxiang</authors> ui
<owners>Zhangwenxiang</owners> spa
<licenseUrl>http://www.qoushui.com</licenseUrl> .net
<projectUrl>http://www.qoushui.com</projectUrl>
<iconUrl>http://www.qoushui.com</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Q.AspNetCore.Tpl</description>
<releaseNotes>整理DOTNETCORE通常須要的文件</releaseNotes>
<copyright>zhangwenxiang</copyright>
<tags>Q.AspNetCore.Tpl</tags>
<dependencies>
<group>
<dependency id="AspNetCoreRateLimit" version="3.0.0" />
<dependency id="CSRedisCore" version="3.0.60" />
<dependency id="QCommon.TimeJob" version="1.0.9" />
<dependency id="System.Text.Encoding.CodePages" version="4.5.1" />
</group>
</dependencies>
</metadata>
<files>
<file src="bin\Release\*\Q.AspNetCore.Tpl.dll" target="lib" />
<file src="*.cs" target="Content" />
<file src="Models\*.cs" target="Content\Models" />
<file src="Controllers\*.cs" target="Content\Controllers" />
<file src="readme.txt" target="" />
<file src="tools\*" target="tools" />
</files>
</package>
@@#
參考
說解決了,但根據他的方法,我並無解決:
https://q.cnblogs.com/q/114299/
https://github.com/NuGet/Home/issues/6548
老外最後也只能出個提示,讓你手工複製
參考
連接文件(沒試過,估計是之前netframe直接添加文件,更新包會覆蓋可能修改過的文件的緣由,因此搞了個LINK),參考
http://blog.stashev.com/linking-a-file-from-a-nuget-package/
彈出readme,功能正常,參考
PS操縱項目文件參考
https://blog.csdn.net/weixin_34417200/article/details/85998228
最後沒辦法,添加了init.ps1用於複製文件,代碼以下,該方法要求VS必須以管理員身份運行,但它工做也不是很穩定
param($installPath, $toolsPath, $package, $project)
#$installPath = "C:\Users\zwx\.nuget\packages\q.aspnetcore.tpl\1.0.9"
#$projectItemPath = "D:\CodeCard\E雲平臺\ZY.OPS\ZY.OPS.Client\Program.cs"
Write-Host "hello"
$projectItemPath = " "
$projectPath = " "
if ($project)
{
$projectItemPath = $project.ProjectItems.Item("Program.cs").Properties.Item("FullPath").Value
$projectPath = [System.IO.Path]::GetDirectoryName($projectItemPath)
}else{
#$installPath = "C:\Users\zwx\.nuget\packages\q.aspnetcore.tpl\1.0.9\tools"
#$projectItemPath = "D:\CodeCard\E雲平臺\ZY.OPS\ZY.OPS.Client\Program.cs"
$projectPath = [System.IO.Path]::GetDirectoryName($installPath)
$installPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$x =New-Object -TypeName System.IO.DirectoryInfo -ArgumentList $installPath
$installPath = $x.Parent.FullName
}
Write-Host "從 $installPath 中複製文件至 $projectPath"
#Write-Host $installPath
#Write-Host $projectPath
#Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject
$contentPath = [System.IO.Path]::Combine($installPath,"content")
$len = $contentPath.Length+1;
ForEach($item in get-ChildItem $contentPath -Recurse)
{
if($item -is [System.IO.FileInfo]){
$targetPath=[System.IO.Path]::Combine($projectPath,$item.FullName.Substring($len))
if([System.IO.File]::Exists($targetPath)){
continue;
}
$tmpPath = [System.IO.Path]::GetDirectoryName($targetPath)
if(![System.IO.Directory]::Exists($tmpPath)){
[System.IO.Directory]::CreateDirectory($tmpPath)
}
[System.IO.File]::Copy($item.FullName,$targetPath,0)
$info = $item.FullName.Substring($len)
Write-Host "copy file: $info"
}
}
@@#
效果圖
不工做的時候切換到PM的控制檯,會發現它試圖工做,可手工執行,參考
https://docs.microsoft.com/zh-cn/nuget/tools/package-manager-console