Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CS8019 Error on Assemblyinfo on temp file MSBuild Server

I am getting a code analysis error on my build server the error is

...NETFramework,Version=v4.6.AssemblyAttributes.cs(3,1): error CS8019:Unnecessary using directive.

This is in a Temp file which Visual Studio creates.

In my project I have "Suppress results from generated code (managed only)" ticked. I would have thought that would be enough.

But I still get the error on the server and locally i get none.

Any ideas?

like image 819
MicroMan Avatar asked Oct 16 '15 15:10

MicroMan


2 Answers

Michal's answer only partially helps here. Yes, you can redirect where that file is written but it will still violate the CS8019 rule.

You have two options:

  1. Also set the <TargetFrameworkMonikerAssemblyAttributeText> property to something that doesn't violate the rule. For instance:

    // &lt;autogenerated /&gt;
    [assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(&quot;$(TargetFrameworkMoniker)&quot;, FrameworkDisplayName = &quot;$(TargetFrameworkMonikerDisplayName)&quot;)]
    
  2. Or, redirect the file to someplace not temporary. In my case I chose to write it to the solution root so all projects would share the file. I then manually edited the file to remove the violations and committed the file along with the rest of my code. The file doesn't get overwritten if it already exists so this will generally be safe.

like image 188
Brennan Fee Avatar answered Oct 27 '22 04:10

Brennan Fee


Googling for CS8019 AssemblyAttributes yielded many interesting articles, such as this blog post. Quoting:

Fortunately for us, MSBuild is flexible enough so we can work around it. The good design is to generate this file into the Intermediate directory (usually called obj), because this is where all transient and temporary files should go during a build process. We can either set this property in our project file:

<PropertyGroup>
    <TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
</PropertyGroup>

Or if your build uses a common .props file, set this property there. This will ensure that your build doesn’t depend on the TEMP directory and is more isolated, repeatable and incremental.

like image 36
Michal Hosala Avatar answered Oct 27 '22 04:10

Michal Hosala