dotnet core nuget软件包在还原时复制内容文件

编程入门 行业动态 更新时间:2024-10-25 13:20:30
本文介绍了dotnet core nuget软件包在还原时复制内容文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我觉得我已经走到了尽头,但希望有人比我在这里了解更多。我有一些 Typescript 文件,尽管这与我无关,因为我对所有内容文件都有此问题。

So I feel like I have come to the end of the rope here, but hoping someone knows more than I do here. I have some Typescript files, though that is mostly irrelevant as I am having this problem with all content files.

我能够生成 nuget ,或更确切地说是 dotnet pack 的nuget程序包,该程序包中包含我的内容文件通过在我的父级项目的 .csproj 中使用它:

I am able to generate a nuget, or more precisely dotnet pack, nuget package that includes my content files in the package by using this in the .csproj of my parent project:

<ItemGroup> <Content Include="Scripts\Utility.ts"> <Pack>true</Pack> <PackagePath>contentFiles\Scripts\;content\Scripts</PackagePath> </Content> </ItemGroup>

我可以浏览生成的 .nupkg 并看到确实在 content\Scripts 和 contentFiles\Scripts 位置中将文件添加到程序包中

I can browse the generated .nupkg and see that indeed the file was added to the package in both the content\Scripts and contentFiles\Scripts locations

问题是,每当我在孩子程序中使用此程序包时, Typescript 都不会复制到任何 child 项目的文件夹,尽管我可以看到它在 .nuget\packages\parent\ ... 文件夹。

The problem is that whenver I consume this package in my 'child' progect, that Typescript never gets copied into any folder of the child project, though I can see it extracted in the .nuget\packages\parent\... folders.

起初,我认为这与 parent 项目中的初始设置有关,可能是这样,但是在尝试了本书中所有内容之后,未能将内容文件复制到 child 项目。然后,我尝试走黑暗的道路,尝试在包的 tools 文件夹中使用 Init.ps1 ,尽管这是不可能进行调试的,它似乎也偶尔会运行(我完全松开并重新安装了程序包,但大部分时间它仍然无法运行。)这可能是这样,但我不知道为什么我无法得到它输出到 Package Manager控制台 ...也许还有希望与 Init.ps1 一起使用,但我似乎无法弄明白。最后,我发现 nuget .targets的潜力文件,但我似乎也可以掌握该如何使用它!我希望获得有关如何完成此操作的反馈。

At first I thought it was something with my initial settings in the parent project, and it may be, but after trying what seems like everything in the book, that fails to copy the content files to the child project. I then tried going the dark path of trying to use Init.ps1 in the tools folder of my package, and though it was impossible to debug, it also seemed to run sporatically (I completely unistalled and reinstalled the package and it still failed to run most of the time.) This could be the way but I don't know why I can't get it to output to the Package Manager Console... maybe there's still hope with Init.ps1 but I can't seem to figure it out. Finally I see some potential with a nuget .targets file but I can's seem to grasp how to use it for my purpose either! I would love some feedback as to how to get this done.

推荐答案

发件人: 宣布支持通用Windows平台的NuGet 3.1

对于使用Nuget v3.1中的project.json文件的项目,从Nuget包中导入内容已被贬值。从那时起,project.json文件就被删除了,而采用了新的.csproj格式。从Nuget包中导入内容仍然可以正常工作,尽管如果使用的是packages.config文件。

Importing content from a Nuget package was depreciated for projects using a project.json file in Nuget v3.1. Since then the project.json file has been dropped in favour of the new .csproj format. Importing content from a Nuget package should still work though if you're using the packages.config file instead.

还提到了其他可用的包管理器

Also mentioned is the fact that there are other package managers available for delivering content.

在我看来,新世界的答案是创建一个包含Utility.js的节点模块,然后让npm将其交付给您的项目。

It looks to me like the answer in the new world is to create a node module containing utility.js and let npm deliver it to your project.

可能的解决方法:

我看着.targets复制文件并得到了这项工作有效,但是它确实可以在每个版本上运行-这可能对您来说不是问题。我不能用它做我想做的事。

I've looked at .targets to copy files and got this working, but it does run on each build - which may or may not be a problem for you. I can't do what I want with it.

在[PackageId] .targets中:

In [PackageId].targets:

<Project xmlns="schemas.microsoft/developer/msbuild/2003"> <!-- Either do this for all scripts in the Scripts/js folder --> <Target Name="CopyScriptsToProject" BeforeTargets="Build"> <Message Text="Copying scripts to project" /> <ItemGroup> <SourceScripts Include="$(MSBuildThisFileDirectory)..\..\content\Scripts\js\**\*.*"/> </ItemGroup> <Copy SourceFiles="@(SourceScripts)" DestinationFiles="@(SourceScripts -> '$(MSBuildProjectDirectory)\wwwroot\js\%(RecursiveDir)%(Filename)%(Extension)')" Condition="!Exists('$(MSBuildProjectDirectory)\wwwroot\js\%(RecursiveDir)%(Filename)%(Extension)')" /> </Target> <!-- Or do this for the individual script --> <Target Name="CopyUtilityScriptToProject" BeforeTargets="Build"> <Copy SourceFiles="$(MSBuildThisFileDirectory)..\..\content\Scripts\js\Utility.js" DestinationFiles="$(MSBuildProjectDirectory)\wwwroot\js\Utility.js" Condition="!Exists('$(MSBuildProjectDirectory)\wwwroot\js\Utility.js')" /> </Target> </Project> <!-- Note: condition can be removed from either if you want it to overwrite each build -->

并在.csproj文件中(用包名替换[PackageId]):

and in the .csproj file (replacing [PackageId] with the name of your package):

<Project Sdk="Microsoft.NET.Sdk"> ... any Globals for source control stuff ... <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <Version>7.0.0</Version> <PackageId>[PackageId]</PackageId> </PropertyGroup> ... any PackageReference stuff ... <ItemGroup Label="Packaging"> <Content Include="build\netcoreapp2.0\[PackageId].targets" PackagePath="build\netcoreapp2.0\[PackageId].targets" /> <!-- Either --> <Content Include="Scripts\js\**\*.*" PackagePath="content\Scripts\js;contentFiles\Scripts\js" /> <!-- or --> <Content Include="Scripts\js\Utility.js" PackagePath="content\Scripts\js;contentFiles\Scripts\js" /> </ItemGroup> </Project>

似乎有一个错误,当< PackageId> [PackageId ]< / PackageId> 没有在.csproj中明确设置,构建目标无效。尽管这很可能是我的开发环境的问题。

There seemed to be a bug whereby when the <PackageId>[PackageId]</PackageId> wasn't set explicitly in the .csproj, the build targets didn't work. Although that may well be an issue with my development environment.

更多推荐

dotnet core nuget软件包在还原时复制内容文件

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

发布评论

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

>www.elefans.com

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