本文介绍了在AssemblyInfo.cs中引用项目时,发布预编译的ASP.NET失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 当我们尝试在发布期间启用 Precompile 的情况下发布ASP.NET应用程序时,它将失败,因为我们在 AssemblyInfo.cs 文件。When we try to publish our ASP.NET application with Precompile during publishing enabled, it will fail because we reference a project in the AssemblyInfo.cs file.这是我们的项目结构: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)在 Project.WebUI 的$ c> AssemblyInfo.cs ,我们引用的是 Project.Resources ,如下所示:In the AssemblyInfo.cs of Project.WebUI we are referencing Project.Resources like this:using Project.Resources;....[assembly: AssemblyVersion(VersionInformation.FileVersion)][assembly: AssemblyFileVersion(VersionInformation.FileVersion)][assembly: AssemblyInformationalVersion(VersionInformation.ProductVersion)] Class VersionInformation 是静态类在 Project.Resources 中。Class VersionInformation is a static class in Project.Resources.所有其他程序集的 AssemblyVersion 也具有这些引用。 All other assemblies also have these references for their AssemblyVersion构建(调试或发布)时,它将顺利通过。 发布 Project.WebUI 项目时,出现以下错误:When we build (Debug or Release) it will pass without any errors.When we publish the Project.WebUI project, we are getting following errors:Severity Code Description Project File Line Suppression StateError 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 我们的发布配置文件如下:Our publishing profile looks like this:[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)为什么会发生此错误,我们该如何解决?Why does this error occur and how can we fix this?这是错误的 Output 日志:------ 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.csProperties\AssemblyInfo.cs(34,28): Error CS0103: The name 'VersionInformation' does not exist in the current contextProperties\AssemblyInfo.cs(35,32): Error CS0103: The name 'VersionInformation' does not exist in the current contextProperties\AssemblyInfo.cs(36,41): Error CS0103: The name 'VersionInformation' does not exist in the current contextProperties\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.WebUI 的code> AssemblyInfo.cs ,但仅此文件。因此,它无法正确引用 Project.Resources 。Apparently during "Publish" the csc.exe tries to compile the AssemblyInfo.cs of our Project.WebUI, but only this file. So it fails to get the correct references to Project.Resources.我的同事为我们提供的解决方案是有效的: The solution my colleague brought works for us: 从所有 AssemblyInfo.cs 文件中删除所有Version属性 在 Project.Resources 项目中创建一个新文件,例如 AssemblyVersion.cs 该文件的唯一内容是这样的版本属性Removing all Version attributes from all AssemblyInfo.cs filesCreate a new file in the Project.Resources project like AssemblyVersion.csThe only content of that file are the version attributes like this [assembly: AssemblyFileVersion(VersionInformation.FileVersion)] 创建一个指向 AssemblyVersion的链接。其他项目中的cs 这篇关于在AssemblyInfo.cs中引用项目时,发布预编译的ASP.NET失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-31 16:56