尽管存在 dll.refresh 文件,但 nuget 包 .dll 未使用 MSBuild 复制到 bin

nuget package .dll not copying to bin with msbuild despite dll.refresh file

提问人:goodsoup 提问时间:11/15/2023 最后编辑:goodsoup 更新时间:11/16/2023 访问量:69

问:

我敢肯定是我做错了什么,可以和比我聪明的人一起看这个。

我遇到的问题是,面向 .NET 4.7.2 的 MSBuild 无法复制文件中引用的 dll,因此构建失败并出现类型缺失错误(显然是因为缺少 .dll),但是如果我复制/粘贴 dll 并且我在移动到新机器之前使用 MSBuild 构建良好的存储库,则在 Visual Studio 中构建正常并在 MSBuild 中构建良好。Visual Studio 2022 和 VisualStudio 2022 生成工具都安装了所有内容bin/nager.publicsuffix.dll.refreshpackages\Nager.PublicSuffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll

MSBuild 输出

MSBuild version 17.8.3+195e7f5a3 for .NET Framework
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe /verbosity:diagnostic C:\Development\test\test.sln
Build started 15/11/2023 11:51:51.
Process = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe"
MSBuild executable path = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.e
xe"
Command line arguments = ""C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.e
xe"  "C:\Development\test\test.sln" /verbosity:diagnostic"
Current directory = "C:\Windows\System32"
MSBuild version = "17.8.3+195e7f5a3"
Some command line switches were read from the auto-response file "C:\Program Files (x86)\Microsoft Visual Studio\2022\B
uildTools\MSBuild\Current\Bin\MSBuild.rsp". To disable this file, use the "-noAutoResponse" switch.

Search paths being used for $(MSBuildExtensionsPath) are C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
\MSBuild;$(MSBuildProgramFiles32)\MSBuild
Search paths being used for $(MSBuildExtensionsPath) are C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
\MSBuild;$(MSBuildProgramFiles32)\MSBuild
Trying to import C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\$(MSBuildToolsVersion)\Solution
File\ImportAfter\* using extensions path C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild
Assembly loaded during Evaluation: Microsoft.IO.Redist, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd
51 (location: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\Microsoft.IO.Redist.dl
l, MVID: d528d43e-4d35-4c28-8aa6-a5ce49a5eba7, AppDomain: [Default])
Property reassignment: $(_GenerateRestoreGraphProjectEntryInputProperties)="
      ExcludeRestorePackageImports=true;
      _RestoreSolutionFileUsed=true;
      SolutionDir=C:\Development\test\;
      SolutionName=test;
      SolutionFileName=test.sln;
      SolutionPath=C:\Development\test\test.sln;
      SolutionExt=.sln;
    " (previous value: "ExcludeRestorePackageImports=true") at C:\Program Files (x86)\Microsoft Visual Studio\2022\Buil
dTools\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets (84,5)
The target "_CheckForInvalidConfigurationAndPlatform" listed in a BeforeTargets attribute at "C:\Program Files (x86)\Mi
crosoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets (601,11)" does not exi
st in the project, and will be ignored.
Initial Properties:
_DirectorySolutionPropsBasePath =
_DirectorySolutionPropsFile = Directory.Solution.props
_DirectorySolutionTargetsBasePath =
_DirectorySolutionTargetsFile = Directory.Solution.targets
_GenerateRestoreGraphProjectEntryInputProperties =
      ExcludeRestorePackageImports=true;
      _RestoreSolutionFileUsed=true;
      SolutionDir=C:\Development\test\;
      SolutionName=test;
      SolutionFileName=test.sln;
      SolutionPath=C:\Development\test\test.sln;
      SolutionExt=.sln;

_RestoreSolutionFileUsed = true
AndroidTargetsPath = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\MDD\Android\V150\
AspNetConfiguration = Debug
Configuration = Debug
CurrentSolutionConfigurationContents = <SolutionConfiguration>
  <ProjectConfiguration Project="{E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1}" AbsolutePath="C:\Development\test" BuildProjec
tInSolution="True">Debug|AnyCPU</ProjectConfiguration>
</SolutionConfiguration>
FrameworkSDKRoot = C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\
GetReferenceNearestTargetFrameworkTaskSupportsTargetPlatformParameter = true
HideWarningsAndErrors = false
iOSTargetsPath = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\MDD\iOS\V150\
IsRestoreTargetsFileLoaded = true
MSBuildAllProjects = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Micros
oft\NuGet\NuGet.targets
MSBuildAssemblyVersion = 17.0
MSBuildBinPath = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin
MSBuildDisableFeaturesFromVersion = 999.999
MSBuildExtensionsPath = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild
MSBuildExtensionsPath32 = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild
MSBuildFileVersion = 17.8.3.51904
MSBuildFrameworkToolsPath = C:\Windows\Microsoft.NET\Framework\v4.0.30319\
MSBuildFrameworkToolsPath32 = C:\Windows\Microsoft.NET\Framework\v4.0.30319\
MSBuildFrameworkToolsPath64 = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
MSBuildFrameworkToolsPathArm64 = C:\Windows\Microsoft.NET\FrameworkArm64\v4.0.30319\
MSBuildFrameworkToolsRoot = C:\Windows\Microsoft.NET\Framework\
MSBuildNodeCount = 1
MSBuildProgramFiles32 = C:\Program Files (x86)
MSBuildProjectDefaultTargets = Build
MSBuildProjectDirectory = C:\Development\test
MSBuildProjectDirectoryNoRoot = Development\test
MSBuildProjectExtension = .metaproj
MSBuildProjectFile = test.sln.metaproj
MSBuildProjectFullPath = C:\Development\test\test.sln.metaproj
MSBuildProjectName = test.sln
MSBuildRuntimeType = Full
MSBuildRuntimeVersion = 4.0.30319
MSBuildSDKsPath = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Sdks
MSBuildSemanticVersion = 17.8.3+195e7f5a3
MSBuildStartupDirectory = C:\Windows\System32
MSBuildToolsPath = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin
MSBuildToolsPath32 = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin
MSBuildToolsPath64 = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\amd64
MSBuildToolsRoot = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild
MSBuildToolsVersion = Current
MSBuildVersion = 17.8.3
NuGetInteractive =
NuGetRestoreTargets = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\..\Common7\IDE\CommonExten
sions\Microsoft\NuGet\NuGet.targets
PackageDownloadSupported = true
Platform = Any CPU
RestoreBuildInParallel = true
RestoreContinueOnError = WarnAndContinue
RestoreRecursive = true
RestoreTaskAssemblyFile = NuGet.Build.Tasks.dll
RestoreUseSkipNonexistentTargets = true
RoslynTargetsPath = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\Roslyn
SDK35ToolsPath = C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\
SDK40ToolsPath = C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8.1 Tools\
SolutionDir = C:\Development\test\
SolutionExt = .sln
SolutionFileName = test.sln
SolutionName = test
SolutionPath = C:\Development\test\test.sln
TargetFrameworkVersion = v4.0
ValidateRuntimeIdentifierCompatibility = false
VCTargetsPath = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\
VCTargetsPath10 = C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\
VCTargetsPath11 = C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\
VCTargetsPath12 = C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\
VCTargetsPath14 = C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\
VisualStudioVersion = 17.0
VsInstallRoot = C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
WindowsSDK80Path =

Initial Items:
SolutionConfiguration
    Debug|Any CPU
        Content = <SolutionConfiguration>
  <ProjectConfiguration Project="{E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1}" AbsolutePath="C:\Development\test" BuildProjec
tInSolution="True">Debug|AnyCPU</ProjectConfiguration>
</SolutionConfiguration>
        Platform = Any CPU
        Configuration = Debug
    Release|Any CPU
        Content = <SolutionConfiguration />
        Platform = Any CPU
        Configuration = Release

test: Defaulting .NET Framework v4.7.2 to the .NET Framework v4.0 version of aspnet_compiler.exe. To change the version
 of the tool used, please set the "ToolPath" parameter with the correct path to the tool.
test: Defaulting .NET Framework v4.7.2 to the .NET Framework v4.0 version of aspnet_compiler.exe. To change the version
 of the tool used, please set the "ToolPath" parameter with the correct path to the tool.
Project "C:\Development\test\test.sln" on node 1 (default targets).
Target "ValidateSolutionConfiguration: (TargetId:2)" in file "C:\Development\test\test.sln.metaproj" from project "C:\D
evelopment\test\test.sln" (entry point):
Task "Error" skipped, due to false condition; (('$(CurrentSolutionConfigurationContents)' == '') and ('$(SkipInvalidCon
figurations)' != 'true')) was evaluated as (('<SolutionConfiguration>
  <ProjectConfiguration Project="{E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1}" AbsolutePath="C:\Development\test" BuildProjec
tInSolution="True">Debug|AnyCPU</ProjectConfiguration>
</SolutionConfiguration>' == '') and ('' != 'true')).
Task "Warning" skipped, due to false condition; (('$(CurrentSolutionConfigurationContents)' == '') and ('$(SkipInvalidC
onfigurations)' == 'true')) was evaluated as (('<SolutionConfiguration>
  <ProjectConfiguration Project="{E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1}" AbsolutePath="C:\Development\test" BuildProjec
tInSolution="True">Debug|AnyCPU</ProjectConfiguration>
</SolutionConfiguration>' == '') and ('' == 'true')).
Using "Message" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5
f7f11d50a3a".
Task "Message" (TaskId:2)
  Task Parameter:Text=Building solution configuration "Debug|Any CPU". (TaskId:2)
  Building solution configuration "Debug|Any CPU". (TaskId:2)
Done executing task "Message". (TaskId:2)
Done building target "ValidateSolutionConfiguration" in project "test.sln".: (TargetId:2)
Target "ValidateToolsVersions: (TargetId:3)" in file "C:\Development\test\test.sln.metaproj" from project "C:\Developme
nt\test\test.sln" (entry point):
Task "Error" skipped, due to false condition; ('$(MSBuildToolsVersion)' == '2.0' and ('$(ProjectToolsVersion)' != '2.0'
 and '$(ProjectToolsVersion)' != '')) was evaluated as ('Current' == '2.0' and ('' != '2.0' and '' != '')).
Done building target "ValidateToolsVersions" in project "test.sln".: (TargetId:3)
Target "ValidateProjects: (TargetId:4)" in file "C:\Development\test\test.sln.metaproj" from project "C:\Development\te
st\test.sln" (entry point):
Task "Warning" skipped, due to false condition; ( ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') )
was evaluated as ( ('Debug' == 'Release') and ('Any CPU' == 'Any CPU') ).
Done building target "ValidateProjects" in project "test.sln".: (TargetId:4)
Target "Build: (TargetId:5)" in file "C:\Development\test\test.sln.metaproj" from project "C:\Development\test\test.sln
" (entry point):
Using "MSBuild" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5
f7f11d50a3a".
Task "MSBuild" (TaskId:3)
  Task Parameter:BuildInParallel=True (TaskId:3)
  Task Parameter:
      Projects=
          C:\Development\test\test.metaproj
                  AdditionalProperties=Configuration=Debug; Platform=Any CPU
                  Configuration=Debug
                  Platform=AnyCPU
                  SkipNonexistentProjects=Build
                  ToolsVersion=Current (TaskId:3)
  Task Parameter:
      Properties=
          BuildingSolutionFile=true
          CurrentSolutionConfigurationContents=<SolutionConfiguration>
    <ProjectConfiguration Project="{E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1}" AbsolutePath="C:\Development\test" BuildProj
  ectInSolution="True">Debug|AnyCPU</ProjectConfiguration>
  </SolutionConfiguration>
          SolutionDir=C:\Development\test\
          SolutionExt=.sln
          SolutionFileName=test.sln
          SolutionName=test
          SolutionPath=C:\Development\test\test.sln (TaskId:3)
  Global Properties: (TaskId:3)
    BuildingSolutionFile=true (TaskId:3)
    CurrentSolutionConfigurationContents=<SolutionConfiguration>
    <ProjectConfiguration Project="{E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1}" AbsolutePath="C:\Development\test" BuildProj
  ectInSolution="True">Debug|AnyCPU</ProjectConfiguration>
  </SolutionConfiguration> (TaskId:3)
    SolutionDir=C:\Development\test\ (TaskId:3)
    SolutionExt=.sln (TaskId:3)
    SolutionFileName=test.sln (TaskId:3)
    SolutionName=test (TaskId:3)
    SolutionPath=C:\Development\test\test.sln (TaskId:3)
  Additional Properties for project "C:\Development\test\test.metaproj": (TaskId:3)
    Configuration=Debug (TaskId:3)
    Platform=Any CPU (TaskId:3)
Project "C:\Development\test\test.sln" (1) is building "C:\Development\test\test.metaproj" (2) on node 1 (default targe
ts).
Target "GetFrameworkPathAndRedistList: (TargetId:6)" in project "C:\Development\test\test.metaproj" (target "Build" dep
ends on it):
Using "GetFrameworkPath" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyTo
ken=b03f5f7f11d50a3a".
Task "GetFrameworkPath" (TaskId:4)
  Output Item(s): _CombinedTargetFrameworkDirectoriesItem=C:\Windows\Microsoft.NET\Framework\v4.0.30319 (TaskId:4)
  Output Item(s): _CombinedTargetFrameworkDirectoriesItem=C:\Windows\Microsoft.NET\Framework\v3.5 (TaskId:4)
  Output Item(s): _CombinedTargetFrameworkDirectoriesItem=C:\Windows\Microsoft.NET\Framework\v3.0 (TaskId:4)
  Output Item(s): _CombinedTargetFrameworkDirectoriesItem=C:\Windows\Microsoft.NET\Framework\v2.0.50727 (TaskId:4)
Done executing task "GetFrameworkPath". (TaskId:4)
Using "CreateItem" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b0
3f5f7f11d50a3a".
Task "CreateItem" (TaskId:5)
  Task Parameter:
      Include=
          C:\Windows\Microsoft.NET\Framework\v4.0.30319\RedistList\*.xml
          C:\Windows\Microsoft.NET\Framework\v3.5\RedistList\*.xml
          C:\Windows\Microsoft.NET\Framework\v3.0\RedistList\*.xml
          C:\Windows\Microsoft.NET\Framework\v2.0.50727\RedistList\*.xml (TaskId:5)
  Output Item(s):
      InstalledAssemblyTables=
          C:\Windows\Microsoft.NET\Framework\v2.0.50727\RedistList\FrameworkList.xml
                  OriginalItemSpec=C:\Windows\Microsoft.NET\Framework\v2.0.50727\RedistList\*.xml (TaskId:5)
Done executing task "CreateItem". (TaskId:5)
Done building target "GetFrameworkPathAndRedistList" in project "test.metaproj".: (TargetId:6)
Target "Build: (TargetId:7)" in project "C:\Development\test\test.metaproj" (entry point):
Task "MSBuild" (TaskId:6)
  Task Parameter:BuildInParallel=True (TaskId:6)
  Task Parameter:
      Properties=
          BuildingSolutionFile=true
          CurrentSolutionConfigurationContents=<SolutionConfiguration>
    <ProjectConfiguration Project="{E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1}" AbsolutePath="C:\Development\test" BuildProj
  ectInSolution="True">Debug|AnyCPU</ProjectConfiguration>
  </SolutionConfiguration>
          SolutionDir=C:\Development\test\
          SolutionExt=.sln
          SolutionFileName=test.sln
          SolutionName=test
          SolutionPath=C:\Development\test\test.sln (TaskId:6)
Done executing task "MSBuild". (TaskId:6)
Task "CreateItem" (TaskId:7)
  Task Parameter:Include=..\test\\Bin\*.refresh (TaskId:7)
  Output Item(s):
      Project_E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1_References_RefreshFile=
          ..\test\Bin\Nager.PublicSuffix.dll.refresh
                  OriginalItemSpec=..\test\\Bin\*.refresh (TaskId:7)
Done executing task "CreateItem". (TaskId:7)
Using "ReadLinesFromFile" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyT
oken=b03f5f7f11d50a3a".
Task "ReadLinesFromFile" (TaskId:8)
  Task Parameter:File=..\test\Bin\Nager.PublicSuffix.dll.refresh (TaskId:8)
  Output Item(s): Project_E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1_References_ReferenceRelPath=packages\Nager.PublicSuffix.
  2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll (TaskId:8)
Done executing task "ReadLinesFromFile". (TaskId:8)
Using "CombinePath" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b
03f5f7f11d50a3a".
Task "CombinePath" (TaskId:9)
  Task Parameter:Paths=packages\Nager.PublicSuffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll (TaskId:9)
  Task Parameter:BasePath=..\test\ (TaskId:9)
  Output Item(s):
      Project_E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1_References=
          ..\test\packages\Nager.PublicSuffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll
                  OriginalItemSpec=packages\Nager.PublicSuffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll (TaskId:
  9)
Done executing task "CombinePath". (TaskId:9)
Task "Copy" skipped, due to false condition; (!Exists('%(Project_E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1_References.Identi
ty)')) was evaluated as (!Exists('..\test\packages\Nager.PublicSuffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll')
).
Using "GetReferenceAssemblyPaths" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, Pu
blicKeyToken=b03f5f7f11d50a3a".
Task "GetReferenceAssemblyPaths" (TaskId:10)
  Task Parameter:TargetFrameworkMoniker=.NETFramework,Version=v4.7.2 (TaskId:10)
  Output Property: Project_E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1__TargetFrameworkDirectories=C:\Program Files %28x86%29\
  Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\ (TaskId:10)
  Output Property: Project_E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1__FullFrameworkReferenceAssemblyPaths=C:\Program Files %
  28x86%29\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\ (TaskId:10)
Done executing task "GetReferenceAssemblyPaths". (TaskId:10)
Using "ResolveAssemblyReference" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, Pub
licKeyToken=b03f5f7f11d50a3a".
Task "ResolveAssemblyReference" (TaskId:11)
  Task Parameter:FullFrameworkFolders=C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.
  7.2\ (TaskId:11)
  Task Parameter:
      SearchPaths=
          {RawFileName}
          {TargetFrameworkDirectory}
          {GAC} (TaskId:11)
  Task Parameter:FindSerializationAssemblies=True (TaskId:11)
  Task Parameter:FindSatellites=True (TaskId:11)
  Task Parameter:
      Assemblies=
          C:\Development\test\packages\Nager.PublicSuffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll
                  OriginalItemSpec=packages\Nager.PublicSuffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll (TaskId:
  11)
  Task Parameter:FindRelatedFiles=True (TaskId:11)
  Task Parameter:TargetFrameworkMoniker=.NETFramework,Version=v4.7.2 (TaskId:11)
  Task Parameter:FindDependencies=True (TaskId:11)
  Task Parameter:TargetFrameworkDirectories=C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramewo
  rk\v4.7.2\ (TaskId:11)
C:\Development\test\test.metaproj : warning MSB3268: The primary reference "C:\Development\test\packages\Nager.PublicSu
ffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll" could not be resolved because it has an indirect dependency on th
e framework assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" which could not b
e resolved in the currently targeted framework. ".NETFramework,Version=v4.7.2". To resolve this problem, either remove
the reference "C:\Development\test\packages\Nager.PublicSuffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll" or reta
rget your application to a framework version which contains "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyTo
ken=cc7b13ffcd2ddd51".
Done executing task "ResolveAssemblyReference". (TaskId:11)
Using "Copy" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f
11d50a3a".
Task "Copy" (TaskId:12)
Done executing task "Copy". (TaskId:12)
Using "AspNetCompiler" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToke
n=b03f5f7f11d50a3a".
Task "AspNetCompiler" (TaskId:13)
  Task Parameter:PhysicalPath=..\test\ (TaskId:13)
  Task Parameter:Force=True (TaskId:13)
  Task Parameter:Debug=True (TaskId:13)
  Task Parameter:ToolPath=C:\Windows\Microsoft.NET\Framework\v4.0.30319 (TaskId:13)
  Task Parameter:FixedNames=False (TaskId:13)
  Task Parameter:TargetPath=PrecompiledWeb\localhost_59420\ (TaskId:13)
  Task Parameter:Updateable=True (TaskId:13)
  Task Parameter:VirtualPath=/localhost_59420 (TaskId:13)

  C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /localhost_59420 -p ..\test\ -u -f -d Precompile
  dWeb\localhost_59420\  (TaskId:13)
  Microsoft (R) ASP.NET Compilation Tool version 4.8.9032.0 (TaskId:13)
  Utility to precompile an ASP.NET application (TaskId:13)
  Copyright (C) Microsoft Corporation. All rights reserved. (TaskId:13)
   (TaskId:13)
c:\Development\test\Default.aspx.cs(3): error CS0246: The type or namespace name 'Nager' could not be found (are you mi
ssing a using directive or an assembly reference?) [C:\Development\test\test.metaproj]
  The command exited with code 1. (TaskId:13)

Done executing task "AspNetCompiler" -- FAILED. (TaskId:13)
Done building target "Build" in project "test.metaproj" -- FAILED.: (TargetId:7)
Done Building Project "C:\Development\test\test.metaproj" (default targets) -- FAILED.

Done executing task "MSBuild" -- FAILED. (TaskId:3)
Done building target "Build" in project "test.sln" -- FAILED.: (TargetId:5)
Done Building Project "C:\Development\test\test.sln" (default targets) -- FAILED.

Deferred Messages

  Detailed Build Summary
  ======================
       (TaskId:0)

  ============================== Build Hierarchy (IDs represent configurations) =======================================
  ==============
  Id                  : Exclusive Time   Total Time   Path (Targets)
  ---------------------------------------------------------------------------------------------------------------------
  -------------- (TaskId:0)
  0                   : 0.016s           0.693s       C:\Development\test\test.sln ()  (TaskId:0)
  . 1                 : 0.678s           0.678s       C:\Development\test\test.metaproj ()  (TaskId:0)

  ============================== Node Utilization (IDs represent configurations) ======================================
  ==============
  Timestamp:            1        Duration   Cumulative
  ---------------------------------------------------------------------------------------------------------------------
  -------------- (TaskId:0)
  638356459118712154:   0        0.016s     0.016s  (TaskId:0)
  638356459118868311:   1        0.678s     0.693s ............. (TaskId:0)
  638356459118868311:   0        0.678s     1.371s ............. (TaskId:0)
  ---------------------------------------------------------------------------------------------------------------------
  --------------
  Utilization:          100.0    Average Utilization: 100.0 (TaskId:0)

Project Evaluation Performance Summary:
       16 ms  C:\Development\test\test.sln.metaproj      1 calls

Project Performance Summary:
      678 ms  C:\Development\test\test.metaproj          1 calls
      693 ms  C:\Development\test\test.sln               1 calls

Target Performance Summary:
        0 ms  ValidateSolutionConfiguration              1 calls
        0 ms  ValidateToolsVersions                      1 calls
        0 ms  ValidateProjects                           1 calls
        0 ms  GetFrameworkPathAndRedistList              1 calls
     1371 ms  Build                                      2 calls

Task Performance Summary:
        0 ms  Message                                    1 calls
        0 ms  GetFrameworkPath                           1 calls
        0 ms  ReadLinesFromFile                          1 calls
        0 ms  CombinePath                                1 calls
        0 ms  GetReferenceAssemblyPaths                  1 calls
        0 ms  Copy                                       1 calls
       16 ms  CreateItem                                 2 calls
       21 ms  ResolveAssemblyReference                   1 calls
      641 ms  AspNetCompiler                             1 calls
      693 ms  MSBuild                                    2 calls

Build FAILED.

"C:\Development\test\test.sln" (default target) (1) ->
"C:\Development\test\test.metaproj" (default target) (2) ->
(Build target) ->
  C:\Development\test\test.metaproj : warning MSB3268: The primary reference "C:\Development\test\packages\Nager.Public
Suffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll" could not be resolved because it has an indirect dependency on
the framework assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" which could not
 be resolved in the currently targeted framework. ".NETFramework,Version=v4.7.2". To resolve this problem, either remov
e the reference "C:\Development\test\packages\Nager.PublicSuffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll" or re
target your application to a framework version which contains "netstandard, Version=2.0.0.0, Culture=neutral, PublicKey
Token=cc7b13ffcd2ddd51".


"C:\Development\test\test.sln" (default target) (1) ->
"C:\Development\test\test.metaproj" (default target) (2) ->
(Build target) ->
  c:\Development\test\Default.aspx.cs(3): error CS0246: The type or namespace name 'Nager' could not be found (are you
missing a using directive or an assembly reference?) [C:\Development\test\test.metaproj]

    1 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.75

重现:

  • 创建新的“ASP.NET 空网站”项目,目标是 4.7.2
  • 通过 NuGet 安装 Nager.PublicSuffix 2.4.0
  • 添加新的 Web 窗体并添加使用nager.publicsuffix
using System;
using System.Web;
using Nager.PublicSuffix;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var host = HttpContext.Current.Request.Url.Host;
        var fileCache = new FileCacheProvider(cacheFileName: "testpublicsuffixcache.dat");
        var domainParser = new DomainParser(new WebTldRuleProvider(cacheProvider: fileCache));
        var domainInfo = domainParser.Parse(host);
        var regdom = domainInfo.RegistrableDomain;
    }
}
  • 在 web.config 中添加到<compilation debug="true" targetFramework="4.7.2"><assemblies><add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" /></assemblies></compilation><httpRuntime targetFramework="4.7.2" /><web.server>
  • 删除 /bin 中的所有内容,仅保留nager.publicsuffix.dll.refresh
  • 打开 CMD 并输入"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe" "C:\Development\test\test.sln"
asp.net msbuild visual-studio-2022 net-standard-2.0 .net-4.7.2

评论

1赞 Jonathan Dodds 11/15/2023
日志显示warning MSB3268: The primary reference "C:\Development\test\packages\Nager.PublicSuffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll" could not be resolved because it has an indirect dependency on the framework assembly "netstandard, Version=2.0.0.0, [...]" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.7.2". To resolve this problem, either remove the reference "[...]\Nager.PublicSuffix.dll" or retarget your application to a framework version which contains "netstandard, Version=2.0.0.0, [...]".
0赞 Jonathan Dodds 11/15/2023
我不确定为什么在这种情况下会发生MSB3268警告。
0赞 goodsoup 11/15/2023
使用 Visual Studio 成功生成以及以前使用 MSBuild 成功生成时,会出现此警告
0赞 Hans Passant 11/16/2023
Quote:将 .NET Framework v4.7.2 默认为 aspnet_compiler.exe 的 .NET Framework v4.0 版本。这听起来不太好。运行 Visual Studio 安装程序,确保勾选 Web 开发工作负载。
0赞 Jonathan Dodds 11/16/2023
aspnet_compiler自 v4.0 以来没有变化。该消息是正常的。
0赞 goodsoup 11/16/2023
我唯一能在构建输出中找到尚未提及的是,但我不知道这意味着什么Task "Copy" skipped, due to false condition; (!Exists('%(Project_E90A1B7E-D6A4-49C7-AB1C-5B6A442541B1_References.Identity)')) was evaluated as (!Exists('..\test\packages\Nager.PublicSuffix.2.4.0\lib\netstandard2.0\Nager.PublicSuffix.dll'))

答: 暂无答案