簡體   English   中英

在AssemblyInfo.cs中引用項目時,發布預編譯的ASP.NET失敗

[英]Publishing precompiled ASP.NET fails when referencing a project in AssemblyInfo.cs

當我們嘗試啟用發布的過程中使用預編譯功能發布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)

Project.WebUIAssemblyInfo.cs ,我們引用的是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的鏈接

在與.SLN相同的文件夾中創建CommonAssemblyInfo.cs,然后將要共享的屬性放在此處。

一次一個項目:選擇“屬性”組,右鍵單擊“添加”>“現有項”,選擇CommonAssemblyInfo.cs,然后從“添加”按鈕菜單中選擇“添加為鏈接”。 從AssemblyInfo.cs中刪除這些屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM