当前位置: 移动技术网 > IT编程>开发语言>.net > Dotnetcore安装nuget包时不能使用content中的文件

Dotnetcore安装nuget包时不能使用content中的文件

2019年06月13日  | 移动技术网IT编程  | 我要评论

dnf巨型发条克里克,大学生征兵条件,亿万宝宝黑道妈

问题:用nuget打包了一个asp.netcore的项目,试图安装到另一个asp.netcore项目中,除了自动添加引用外,还希望自动释放一些文件以供修改。这些操作以前在netframe中是正常的,脚本如下

@@@code

<?xml version="1.0"?>

<package>

<metadata>

<id>q.aspnetcore.tpl</id>

<version>1.0.7</version>

<title>q.aspnetcore.tpl</title>

<authors>zhangwenxiang</authors>

<owners>zhangwenxiang</owners>

<licenseurl>http://www.qoushui.com</licenseurl>

<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://github.com/nuget/home/issues/6548

老外最后也只能出个提示,让你手工复制

参考

https://weblog.west-wind.com/posts/2018/jan/29/distributing-content-and-showing-a-readme-file-in-a-net-core-nuget-package

 

   

链接文件(没试过,估计是以前netframe直接添加文件,更新包会覆盖可能修改过的文件的原因,所以搞了个link),参考

   

弹出readme,功能正常,参考

https://weblog.west-wind.com/posts/2018/jan/29/distributing-content-and-showing-a-readme-file-in-a-net-core-nuget-package

   

ps操纵项目文件参考

   

   

ps的工作原理参考

 

   

最后没办法,添加了init.ps1用于复制文件,代码如下,该方法要求vs必须以管理员身份运行,但它工作也不是很稳定

@@@code

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的控制台,会发现它试图工作,可手工执行,参考

   

   

  

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网