使用.NetCore RC2自动执行Nuget软件包推送 [英] Automating Nuget Package Push With .NetCore RC2

查看:78
本文介绍了使用.NetCore RC2自动执行Nuget软件包推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发.NET Core库,该库将在另一个项目中用作NuGet包.

I am currently working on a .NET Core library that I am going to use as a NuGet package in another project.

我已经能够使用项目目录中的"dotnet pack"命令成功打包该项目,并将该程序包上传到MyGet.

I have been able to successfully package the project using the "dotnet pack" command in the project directory, and upload that package to MyGet.

我希望通过使用"nuget push"命令来自动完成NuGet软件包的推送过程.

I would prefer to automate this process of pushing the NuGet package by using the "nuget push" command.

我的问题是,在project.json文件中定义的"scripts"属性似乎没有在打包或构建时执行.我希望这些脚本将在发生相应事件时执行,但是它们似乎没有任何作用,因为无论构建时是否带有冗长的标记,我在构建控制台时都看不到任何输出.

My issue is that the "scripts" property defined in the project.json file does not seem to be executed on pack or build. I expected that these scripts would be executed when the corresponding event occurs, but they seem to have no effect as I do not see anything output to console when I build, with or without he verbose tag.

我了解MyGet能够基于Git存储库更新软件包提要,但是我想了解当前使用project.json执行脚本是否存在问题.理想情况下,我想在包成功执行后使用nuget push命令.

I understand that MyGet is able to update a package feed based on a Git repository, but I would like to understand if there is some issue with executing a script currently using a project.json. Ideally I want to use the nuget push command after pack successfully executes.

这是我的project.json文件:

Here is my project.json file :

{
  "version": "0.0.1",
  "scripts": {
    "postbuild": [ "echo build" ],
    "prebuild": "echo build",
    "postpack": "echo build",
    "postpublish": "echo build",
    "postrestore": "echo build",
    "prepack": "echo build",
    "prepare": "echo build",
    "prepublish": "echo build",
    "prerestore": "echo build"
  },

  "dependencies": {
    "NETStandard.Library": "1.5.0-rc2-24027"
  },

  "frameworks": {
    "netstandard1.5": {
    }
  },
  "buildOptions": {
    "allowUnsafe": false,
    "debugType": "portable",
    "emitEntryPoint": false,
    "xmlDoc": false
  },
  "commands": { },
  "packOptions": {
    "files": {
      "include": "%project:Directory%/bin/release/*.nupkg"
    }
  },
  "configurations": {
    "Debug": {
      "buildOptions": {
        "define": [ "DEBUG", "TRACE" ]
      }
    },
    "Release": {
      "buildOptions": {
        "define": [ ]
      }

    }
  }

}

推荐答案

RC2将prebuild和postbuild替换为precompile和postcompile.

RC2 replaced prebuild and postbuild with precompile and postcompile.

您可以使用后编译功能自动生成nupkg,并将软件包使用推送到nuget服务器

You can use the postcompile to automatically generate the nupkg and to push the package to a nuget server using

"scripts": {
    "postcompile": [
  "dotnet pack --no-build",
  "\"%project:Directory%\\..\\..\\nuget.exe\" push \"%project:Directory%\\bin\\%compile:Configuration%\\%project:Name%.%project:Version%.nupkg\" -source nugetserver -ApiKey key"
]
  }

这将使用项目目录中存在的project.json文件自动调用dotnet包.然后它将nuget包推送到指定的nuget服务器.

This will automatically call the dotnet pack using the project.json file that exists in the project directory. Then it will push the nuget package to the specified nuget server.

很遗憾,没有变量可以指定构建配置,因此在上述路径中,当您在调试和发行配置之间切换时,必须手动更改它.

上面使用%compile:Configuration%指定当前的构建配置.

The above uses %compile:Configuration% to specify the current build configuration.

当前构建配置的答案来自 如何基于以下命令运行脚本ASP.NET Core RC2中的解决方案配置

The answer to the current build configuration comes from How to run scripts based on solution configuration in ASP.NET Core RC2

Visual Studio 2017

在Visual Studio 2017中,您可以通过编辑csproj文件并使用以下命令来使用dotnet nuget push命令

In Visual Studio 2017 you can use the dotnet nuget push command by editing the csproj file and using the following command

<Target Name="PushPackage" AfterTargets="Pack">
    <Exec Command="dotnet nuget push &quot;$(MSBuildProjectDirectory)\bin\$(Configuration)\$(AssemblyName).$(Version).nupkg&quot; -s nugetserver -k apikey" />
</Target>

这篇关于使用.NetCore RC2自动执行Nuget软件包推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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