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?
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.
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:
Also set the <TargetFrameworkMonikerAssemblyAttributeText
> property to something that doesn't violate the rule. For instance:
// <autogenerated />
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute("$(TargetFrameworkMoniker)", FrameworkDisplayName = "$(TargetFrameworkMonikerDisplayName)")]
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.