Reputation: 2229
I am working on net core application. I am building my application in jenkins using docker. My sample repository is at
Below is my command to build the application.
docker build -t jenkinspipeline/jenkins -f Dockerfile .
Below is my .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>
When I start build in jenkins I get the below error
obj/Release/netcoreapp2.1/jenkins.RazorAssemblyInfo.cs(11,12): error CS0579: Duplicate 'Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute' attribute [/app/jenkins.csproj] obj/Release/netcoreapp2.1/jenkins.RazorAssemblyInfo.cs(12,12): error CS0579: Duplicate 'Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute' attribute [/app/jenkins.csproj] The command '/bin/sh -c dotnet publish -c Release -o output' returned a non-zero code: 1
What I tried so far is,
Deleted bin and object folder and rebuild-ed. Added GenerateAssemblyInfo as false in .csproj Restarted Jenkins
I added below configuration as per
https://johnkoerner.com/csharp/dealing-with-duplicate-attribute-errors-in-net-core/
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
This also dint work for me. Below is my Jenkins.RazorAssemblyInfo.cs file which I commented and tried but dint work out.
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.
Nothing worked for me. Can someone help me to figure out the issue? Any help would be greatly appreciated. Thanks in advance
Upvotes: 0
Views: 1728
Reputation: 30056
There are multiple issues in your repository:
Jenkins.sln and Jenkins.csproj
in your project. Remove useless content.JenkinsPipeLine\Jenkins\Jenkins
For the dockerfile in JenkinsPipeLine\Jenkins\Jenkins
, its image is wrong, your project target netcoreapp2.1
, you image should be mcr.microsoft.com/dotnet/core/sdk:2.1
. And the dockerfile is
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"]
Run the command docker build -t jenkins -f Dockerfile .
from JenkinsPipeLine\Jenkins\Jenkins
Upvotes: 1