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.
This is our project structure:
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)
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 is a static class in Project.Resources.
All other assemblies also have these references for their AssemblyVersion
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 State Error The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?) Project.WebUI PropertiesAssemblyInfo.cs 3 Error The name 'VersionInformation' does not exist in the current context Project.WebUI PropertiesAssemblyInfo.cs 34 Error The name 'VersionInformation' does not exist in the current context Project.WebUI PropertiesAssemblyInfo.cs 35 Error The name 'VersionInformation' does not exist in the current context Project.WebUI PropertiesAssemblyInfo.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?
Here’s the Output log of the error:
------ Publish started: Project: Project.WebUI, Configuration: Release Any CPU ------ Connecting to C:BuildArtifacts... Transformed Web.config using C:DevelopmentProject.WebUIWeb.Release.config into objReleaseTransformWebConfigtransformedWeb.config. Copying all files to temporary location below for package/publish: objReleaseAspnetCompileMergeSource. C:WINDOWSMicrosoft.NETFrameworkv4.0.30319aspnet_compiler.exe -v -p C:DevelopmentProject.WebUIobjReleaseAspnetCompileMergeSource -c C:DevelopmentProject.WebUIobjReleaseAspnetCompileMergeTempBuildDir C:Program Files (x86)Microsoft Visual Studio2017CommunityMSBuild15.0BinRoslyncsc.exe /out:objReleaseAssemblyInfoAssemblyInfo.dll /target:library PropertiesAssemblyInfo.cs PropertiesAssemblyInfo.cs(34,28): Error CS0103: The name 'VersionInformation' does not exist in the current context PropertiesAssemblyInfo.cs(35,32): Error CS0103: The name 'VersionInformation' does not exist in the current context PropertiesAssemblyInfo.cs(36,41): Error CS0103: The name 'VersionInformation' does not exist in the current context PropertiesAssemblyInfo.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?)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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:
- Removing all Version attributes from all
AssemblyInfo.csfiles - Create a new file in the
Project.Resourcesproject likeAssemblyVersion.cs -
The only content of that file are the version attributes like this
[assembly: AssemblyFileVersion(VersionInformation.FileVersion)]
-
Create a link to
AssemblyVersion.csin every other project
Method 2
Create CommonAssemblyInfo.cs in the same folder as the .SLN and put the attributes you like to share there.
One project at a time: Select the Properties group, right-click Add > Existing Item, select CommonAssemblyInfo.cs and choose Add As Link from the Add button menu. Remove those attributes from AssemblyInfo.cs.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0