Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在AssemblyInfo.cs中引用项目时,发布预编译的ASP.NET失败_C#_Asp.net_.net - Fatal编程技术网

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

C# 在AssemblyInfo.cs中引用项目时,发布预编译的ASP.NET失败,c#,asp.net,.net,C#,Asp.net,.net,当我们尝试在启用发布期间预编译的情况下发布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

当我们尝试在启用发布期间预编译的情况下发布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.WebUI的
AssemblyInfo.cs
中,我们引用了Project。资源如下:

using Project.Resources;

....

[assembly: AssemblyVersion(VersionInformation.FileVersion)]
[assembly: AssemblyFileVersion(VersionInformation.FileVersion)]
[assembly: AssemblyInformationalVersion(VersionInformation.ProductVersion)]
[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)
类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  
我们的发布配置文件如下所示:

using Project.Resources;

....

[assembly: AssemblyVersion(VersionInformation.FileVersion)]
[assembly: AssemblyFileVersion(VersionInformation.FileVersion)]
[assembly: AssemblyInformationalVersion(VersionInformation.ProductVersion)]
[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.WebUI
AssemblyInfo.cs
,但仅编译此文件。因此,它无法获得对
Project.Resources
的正确引用

我的同事为我们带来的解决方案:

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

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


在与.SLN相同的文件夹中创建CommonAssemblyInfo.cs,并将要共享的属性放在那里


一次一个项目:选择属性组,右键单击添加>现有项,选择CommonAssemblyInfo.cs并从添加按钮菜单中选择添加为链接。从AssemblyInfo.cs中删除这些属性

非常感谢你。您是否已经注意到了这样做的任何副作用?整个过程唯一的负面影响是,由于预编译视图,我们的Jenkins构建现在需要很长时间。除此之外,到目前为止还没有任何问题,特别是AssemblyInfo的解决方案运行良好:-)