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?
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: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.
TargetFrameworkMonikerAssemblyAttributesPath
property does not remove the warning. It relocates the file that generates the warning, which will prove useful.TargetFrameworkMonikerAssemblyAttributeText
property does not work. It appears that this property is overwritten by the target that generates this file. (In MSBuild 14.0, the property is overwritten by the target_SetTargetFrameworkMonikerAttribute
in the file Microsoft.CSharp.CurrentVersion.targets and is later being referred to in the targetGenerateTargetFrameworkMonikerAttribute
in file Microsoft.Common.CurrentVersion.targets.)(Working solution) Setting the
TargetFrameworkMonikerAssemblyAttributesFileClean
to false will prevent the file from being overwritten if it already exists. You can thus let the build script generate it, fix theusing ...;
lines manually, save it and see that it is not regenerated when rebuilding. At this point, placing the file in a non-temporary path makes sense.Adding the following to a SharedBuildScript.msbuild.xml file and referring to that within individual project files ensures that they all refer to the same single file:
Googling for CS8019 AssemblyAttributes yielded many interesting articles, such as this blog post. Quoting: