gpt4 book ai didi

c# - 引用 AssemblyInfo.cs 中的项目时发布预编译的 ASP.NET 失败

转载 作者:行者123 更新时间:2023-11-30 15:16:51 28 4
gpt4 key购买 nike

当我们尝试在启用Precompile during publishing 的情况下发布我们的 ASP.NET 应用程序时,它将失败,因为我们引用了 AssemblyInfo.cs 中的项目。文件。

这是我们的项目结构:

Project.WebUI (ASP.NET MVC App on .NET 4.6.2)
Project.Resources (Class Library on .NET 4.6.2)
Project.Domain (Class Library on .NET 4.6.2)
Project.Services (Class Library on .NET 4.6.2)

AssemblyInfo.csProject.WebUI 中,我们像这样引用 Project.Resources:

using Project.Resources;

....

[assembly: AssemblyVersion(VersionInformation.FileVersion)]
[assembly: AssemblyFileVersion(VersionInformation.FileVersion)]
[assembly: AssemblyInformationalVersion(VersionInformation.ProductVersion)]

VersionInformation 类是 Project.Resources 中的静态类。

所有其他程序集的 AssemblyVersion 也有这些引用

当我们构建(调试或发布)时,它将毫无错误地通过。当我们发布 Project.WebUI 项目时,出现以下错误:

Severity    Code    Description Project File    Line    Suppression State
Error The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?) Project.WebUI Properties\AssemblyInfo.cs 3
Error The name 'VersionInformation' does not exist in the current context Project.WebUI Properties\AssemblyInfo.cs 34
Error The name 'VersionInformation' does not exist in the current context Project.WebUI Properties\AssemblyInfo.cs 35
Error The name 'VersionInformation' does not exist in the current context Project.WebUI Properties\AssemblyInfo.cs 36

我们的发布配置文件如下所示:

[X] Delete all existing files prior to publish
[X] Precompile during publishing

Precompile Options
[ ] Allow precompiled site to be updatable
[ ] Emit debug information

Merge Options
[ ] Do not merge
[ ] Do not merge. Create a separate assembly for each page and control
[X] Merge all outputs to a single assembly
"Project.Views"
[X] Treat as library component (remove the AppCode.compiled file)

为什么会出现此错误,我们该如何解决?

这是错误的输出日志:

------ Publish started: Project: Project.WebUI, Configuration: Release Any CPU ------
Connecting to C:\BuildArtifacts\...
Transformed Web.config using C:\Development\Project.WebUI\Web.Release.config into obj\Release\TransformWebConfig\transformed\Web.config.
Copying all files to temporary location below for package/publish:
obj\Release\AspnetCompileMerge\Source.
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v \ -p C:\Development\Project.WebUI\obj\Release\AspnetCompileMerge\Source -c C:\Development\Project.WebUI\obj\Release\AspnetCompileMerge\TempBuildDir
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\csc.exe /out:obj\Release\AssemblyInfo\AssemblyInfo.dll /target:library Properties\AssemblyInfo.cs
Properties\AssemblyInfo.cs(34,28): Error CS0103: The name 'VersionInformation' does not exist in the current context
Properties\AssemblyInfo.cs(35,32): Error CS0103: The name 'VersionInformation' does not exist in the current context
Properties\AssemblyInfo.cs(36,41): Error CS0103: The name 'VersionInformation' does not exist in the current context
Properties\AssemblyInfo.cs(3,7): Error CS0246: The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?)

最佳答案

显然在“发布”期间,csc.exe 尝试编译我们的 Project.WebUIAssemblyInfo.cs,但只有这个文件.因此它无法获得对 Project.Resources 的正确引用。

我同事带来的解决方案对我们有效:

  • 从所有 AssemblyInfo.cs 文件中删除所有 Version 属性
  • Project.Resources 项目中创建一个新文件,例如 AssemblyVersion.cs
  • 该文件的唯一内容是这样的版本属性

    [assembly: AssemblyFileVersion(VersionInformation.FileVersion)]
  • 在每个其他项目中创建指向 AssemblyVersion.cs 的链接

关于c# - 引用 AssemblyInfo.cs 中的项目时发布预编译的 ASP.NET 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48418666/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com