You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Kendo .dll生成的GitHub Package?遇NuGet引用问题求示例

完整步骤:将本地Kendo .dll打包为GitHub可用的NuGet包并实现CI/CD

1. 创建载体类库项目

  • 打开Visual Studio,创建匹配Kendo版本的.NET Framework类库项目(Kendo v2015.1.408.545通常对应.NET Framework 4.5),命名如Kendo.Wrapper.v2015
  • 删除自动生成的Class1.cs文件

2. 嵌入Kendo.dll并配置引用

  • 将本地的Kendo.dll复制到项目根目录下新建的Libs文件夹中
  • 右键项目 → 添加 → 引用 → 浏览选中Libs/Kendo.dll
  • 修改引用属性:
    • 「复制本地」设为False(避免重复复制,依赖包会自动包含)
    • 「嵌入互操作类型」保持默认(Kendo为.NET库,无需启用)

3. 配置项目文件生成NuGet包

  • 右键项目 → 卸载项目 → 编辑.csproj文件,添加以下配置:
<PropertyGroup>
  <!-- NuGet包核心信息 -->
  <PackageId>Kendo.Wrapper.v2015</PackageId>
  <Version>1.0.0</Version>
  <Authors>你的用户名</Authors>
  <Description>Kendo UI v2015.1.408.545 .NET库封装包</Description>
  <PackageProjectUrl>https://github.com/你的用户名/你的仓库名</PackageProjectUrl>
  <RepositoryUrl>https://github.com/你的用户名/你的仓库名</RepositoryUrl>
  <!-- 禁用默认构建输出,只包含指定的dll -->
  <IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>

<ItemGroup>
  <!-- 将Kendo.dll打包到NuGet的对应框架目录 -->
  <None Include="Libs\Kendo.dll">
    <Pack>true</Pack>
    <PackagePath>lib\net45</PackagePath> <!-- 与Kendo目标框架保持一致 -->
  </None>
</ItemGroup>
  • 保存后重新加载项目

4. 本地测试打包与验证

  • 打开命令行,进入项目根目录,执行打包命令:
dotnet pack --configuration Release
  • 打包完成后,在bin/Release目录下会生成Kendo.Wrapper.v2015.1.0.0.nupkg
  • 新建测试项目,添加本地NuGet包,尝试引用Kendo命名空间验证:
using Kendo.Mvc;

public class TestController : Controller
{
    public ActionResult Index()
    {
        var gridBuilder = new GridBuilder<TestModel>(); // 测试实例化Kendo类
        return View();
    }
}
  • 若能正常编译运行,说明包配置无误

5. 上传NuGet包到GitHub Packages

  • 在GitHub仓库的「Settings → Packages」中启用GitHub Packages
  • 生成含write:packages权限的个人访问令牌(PAT)
  • 命令行登录GitHub Packages源:
dotnet nuget add source --name github https://nuget.pkg.github.com/你的用户名/index.json --username 你的用户名 --password 你的PAT令牌
  • 上传包:
dotnet nuget push "bin/Release/Kendo.Wrapper.v2015.1.0.0.nupkg" --source github

6. CI/CD中引用NuGet包

  • 在目标项目的.csproj中添加GitHub Packages源:
<ItemGroup>
  <PackageSource>
    <Clear />
    <Add Key="nuget.org" Value="https://api.nuget.org/v3/index.json" />
    <Add Key="github" Value="https://nuget.pkg.github.com/你的用户名/index.json" />
  </PackageSource>
</ItemGroup>
  • 添加包引用:
<ItemGroup>
  <PackageReference Include="Kendo.Wrapper.v2015" Version="1.0.0" />
</ItemGroup>
  • 示例GitHub Actions workflow文件(/.github/workflows/deploy.yml):
name: Deploy
on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: windows-latest # Kendo v2015适配Windows环境
    steps:
    - uses: actions/checkout@v4
    - name: Setup .NET Framework
      uses: actions/setup-dotnet@v4
      with:
        dotnet-version: '4.8.x'
    - name: Add GitHub NuGet Source
      run: dotnet nuget add source --name github https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }}
    - name: Restore Dependencies
      run: dotnet restore
    - name: Build Project
      run: dotnet build --configuration Release --no-restore
    - name: Publish
      run: dotnet publish --configuration Release --no-build --output ./publish

关键注意事项

  • 保持目标框架一致:载体项目、NuGet包路径、目标项目的.NET框架必须与Kendo.dll的框架版本匹配
  • GitHub权限配置:若跨仓库引用包,需确保Actions使用的令牌拥有对应Packages的访问权限

内容的提问来源于stack exchange,提问作者Ramesh_kadubry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 19:03:25