错误CS8137:无法定义利用元组的类或成员

时间:2019-10-14 21:07:47

标签: .net

我正在尝试在Docker容器中构建针对4.6.1的.Net Framework解决方案。 我已经尽了最大的努力来复制Visual Studio环境,但是由于某些奇怪的原因,我不断遇到以下错误:

error CS0246: The type or namespace name 'DbSet<>' could not be found (are you missing a using directive or an assembly reference?)
error CS8137: Cannot define a class or member that utilizes tuples because the compiler required type 'System.Runtime.CompilerServices.TupleElementNamesAttribute' cannot be found. Are you missing a reference?
error CS8179: Predefined type 'System.ValueTuple`2' is not defined or imported

大约有74个CS0246错误的实例。

奇怪的是,我看到过多次提到同一问题,但是相同的解决方案对我不起作用。似乎在大多数情况下,将System.ValueTuple引用添加到.csproj和/或packages.config可以解决错误。但是,我的项目从一开始就具有这些引用,并且似乎完全忽略了它们。

我也尝试过切换基本映像,以排除在4.7.1环境中构建的应用程序。

我尝试通过nuget cli手动安装System.ValueTuple,但结果仍然相同。

我尝试将.dll从主机复制到容器,但这仍然无法正常工作。

我怀疑也许在Visual Studio中安装了4.7+框架的目标包/开发人员工具可能会引起问题?但是没有这些,我无法安装VS,因为它们是我需要使用的工作负载所必需的(如果我错了,请纠正我)。

我对.NET或Visual Studio一点都不熟悉,而且我已经花了数周的时间来进行调整,但没有任何改善。任何帮助和建议,将不胜感激。我真的希望它的细节小而愚蠢。

.csproj的相关行:

<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
 <HintPath>..\..\..\..\BuildSolutions\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>

packages.config:

<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />

Dockerfile(用于构建应用程序的映像):

# escape=`
FROM mcr.microsoft.com/dotnet/framework/aspnet:3.5-20191008-windowsservercore-1803
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Install Chocolatey and copy files into container
RUN Install-PackageProvider -Name chocolatey -Force
COPY \files\ \files\
WORKDIR \files\

# Install Visual Studio and MSBuild
RUN ./vs_professional_2017.exe --passive --wait --cache --norestart `
--add Microsoft.VisualStudio.Workload.NativeDesktop --add `
Microsoft.VisualStudio.Component.Debugger.JustInTime --add `
Microsoft.VisualStudio.Component.VC.v141.x86.x64 --add `
Microsoft.VisualStudio.Component.VC.DiagnosticTools --add `
Microsoft.VisualStudio.Component.Windows10SDK.17763 --add `
Microsoft.VisualStudio.Component.VC.CMake.Project --add `
Microsoft.VisualStudio.Component.VC.v141.ATL --add `
Microsoft.VisualStudio.Component.VC.v141.MFC --add `
Microsoft.VisualStudio.Component.Windows10SDK.17134 --add `
Microsoft.VisualStudio.Workload.ManagedDesktop --add `
Microsoft.Net.ComponentGroup.TargetingPacks.Common --add `
Microsoft.ComponentGroup.Blend --add `
Microsoft.VisualStudio.Component.EntityFramework --add `
Microsoft.VisualStudio.Component.DiagnosticTools --add `
Microsoft.NetCore.ComponentGroup.DevelopmentTools.2.1. --add `
Microsoft.NetCore.Component.DevelopmentTools --add `
Microsoft.VisualStudio.Component.Wcf.Tooling --add `
Microsoft.VisualStudio.Component.SQL.LocalDB.Runtime --add `
Microsoft.VisualStudio.Workload.NetWeb --add `
Microsoft.NetCore.Component.Web --add `
Microsoft.VisualStudio.Component.AppInsights.Tools --add `
Microsoft.VisualStudio.Component.WebDeploy --add `
Microsoft.VisualStudio.Workload.Azure --add `
Microsoft.Component.Azure.DataLake.Tools --add `
Microsoft.VisualStudio.Component.Azure.ResourceManager.Tools --add `
Microsoft.VisualStudio.Component.Azure.Waverton --add `
Microsoft.VisualStudio.Workload.Node --add `
Microsoft.VisualStudio.Component.Common.Azure.Tools --add `
Microsoft.VisualStudio.Component.VC.CoreIde --add `
Microsoft.VisualStudio.Workload.Data --add `
Microsoft.VisualStudio.Component.SQL.SSDT --includeRecommended 


WORKDIR C:\

# Set environment path inside container
ENV NUGET_PATH="C:\files" `
    MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin" `
    DOTNET_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib" 

RUN $env:PATH = $env:NUGET_PATH + ';' + $env:MSBUILD_PATH + ';' + $env:DOTNET_PATH + ';' + $env:PATH; `
    [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine)


ENTRYPOINT ["powershell"]

Dockerfile(用于实际构建应用程序):

FROM mcr.microsoft.com/dotnet/framework/runtime:3.5-20191008-windowsservercore-1803
WORKDIR /phoenix4.0-app
EXPOSE 80



####################
# Build Stage
####################
FROM djwhorton/msbuild:netfx-4.6.1 AS builder
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Insert Env Variables
ARG BUILD_NUM
ARG JFROG_USERNAME
ARG JFROG_PASSWORD
ENV ENV_BUILD_NUM=$BUILD_NUM
ENV ENV_JFROG_USERNAME=$JFROG_USERNAME
ENV ENV_JFROG_PASSWORD=$JFROG_PASSWORD

# Copy application code to container
WORKDIR C:/
COPY BackEnd/ /BackEnd/
COPY Database/ /Database/

# Add credentials for nuget to access Artifactory
RUN nuget sources Add -Name Artifactory -Source https://carestreamdental.jfrog.io/carestreamdental/api/nuget/eservices-nuget -username $env:ENV_JFROG_USERNAME -password $env:ENV_JFROG_PASSWORD; \
nuget setapikey $env:ENV_JFROG_USERNAME:$env:ENV_JFROG_PASSWORD -Source Artifactory

# nuget restore
RUN msbuild -restore BackEnd/BuildSolutions/CSD.Phoenix.Backend.sln
RUN msbuild -restore BackEnd/EServices/CSD.ES.PartnerAccess.API/CSD.ES.PartnerAccess.API.csproj -PackagesDirectory BackEnd/EServices/CSD.ES.PartnerAccess.API/packages/


# build CSD.Phoenix.Backend.sln
RUN msbuild BackEnd/BuildSolutions/CSD.Phoenix.Backend.sln -t:Clean,Build -p:Configuraton=Release

0 个答案:

没有答案