我正在研究网络核心应用程序。我正在使用 docker 在 jenkins 中构建我的应用程序。我的示例存储库位于
https://github.com/niranjan2020/JenkinsPipeLine
下面是我构建应用程序的命令。
docker build -t jenkinspipeline/jenkins -f Dockerfile .
下面是我的.csproj。
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.0.2105168" />
</ItemGroup>
</Project>
当我开始在 jenkins 中构建时,我收到以下错误
obj/Release/netcoreapp2.1/jenkins.RazorAssemblyInfo.cs(11,12(: 错误 CS0579:重复 'Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute' 属性 [/app/jenkins.csproj] obj/Release/netcoreapp2.1/jenkins.RazorAssemblyInfo.cs(12,12(: 错误 CS0579:重复 'Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute' 属性 [/app/jenkins.csproj] 命令 '/bin/sh -c dotnet publish -c 发布 -o 输出' 返回非零代码:1
到目前为止,我尝试的是,
删除了垃圾箱和对象文件夹并重建。 在 .csproj 中添加了 GenerateAssemblyInfo 作为 false 重新启动的詹金斯
我按照以下配置添加了
https://johnkoerner.com/csharp/dealing-with-duplicate-attribute-errors-in-net-core/
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
这对我也不起作用。 下面是我的Jenkins.RazorAssemblyInfo.cs文件,我评论并尝试过,但效果不佳。
using System;
using System.Reflection;
[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute("Jenkins.Views")]
[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute("2.1")]
[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute("MVC-2.1")]
[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute("MVC-2.1", "Microsoft.AspNetCore.Mvc.Razor.Extensions")]
// Generated by the MSBuild WriteCodeFragment class.
什么都不适合我。有人可以帮助我解决问题吗?任何帮助将不胜感激。提前致谢
存储库中存在多个问题:
- 清理您的项目,您的项目中有多个 leve
Jenkins.sln and Jenkins.csproj
。删除无用的内容。 - 我用你的
JenkinsPipeLineJenkinsJenkins
做了一个测试 -
对于
JenkinsPipeLineJenkinsJenkins
中的 dockerfile ,它的镜像是错误的,你的项目目标netcoreapp2.1
,你的镜像应该是mcr.microsoft.com/dotnet/core/sdk:2.1
的。码头工人文件是FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-env WORKDIR /app COPY *.csproj ./ RUN dotnet restore COPY . ./ RUN dotnet publish -c Release -o output # Runtime image FROM mcr.microsoft.com/dotnet/core/aspnet:2.1 WORKDIR /app COPY --from=build-env /app/output . ENTRYPOINT ["dotnet", "jenkins.dll"]
-
从
JenkinsPipeLineJenkinsJenkins
docker build -t jenkins -f Dockerfile .
运行命令