Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute
Steps to reproduce
I am using 1.0.0-preview4-004079 prerelase version of .Net core.
My csproj file is following:
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Collections.Specialized">
<Version>4.0.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
After dotnet restore I don't get any error or warning, but after dotnet build I am getting 9 errors like error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute .
Is this because of incorrect version of System.Collections.Specialized and how to fix this?
Ran into that myself when already having a Properties\AssemblyInfo.cs in the project with an [assembly: AssemblyCompany("..")] attribute.
The SDK now has targets that emit these attributes to a generated AssemblyInfo.cs that is included during build. (Here)
If this is indeed your problem, you can either move all existing Attributes to the .csproj by adding a <Company>Evilcorp</Company> property or suppress the generation of the attribute by specifying <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>.
In my case I need to remove bin and obj folders after any change, do restore and then build. This fixed issue.
@SamvelS we need to improve that experience. As @dasMulli suggests, there are already flags in place for disabling any auto-generation of attributes that you are explicitly specifying. What attributes are you defining in assemblyinfo.cs? I'd first like to give you the right content to put in the csproj file, then hear your and @dasMulli's thoughts on how to improve this UX.
/cc @livarcocc @nguerrera
/cc @blackdwarf
@piotrpMSFT I didn't specify any argument at all. Everything is what was generated. The problem was with inner project. I was trying to create solution like structure, created inner folder (on same directory as root csproj file) and added new project to it.
After that first was building inner project (which was generating bin and obj folders) and after that root project.
I removed inner bin/obj folders and started to build only root.
Also deleting bin/obj folders every time I need to call 'dotnet restore'.
I was thinking that I will need to add reference to inner project but it is working without adding anything to root folder, which can cause lots of issues as on .Net many projects in solution can have classes with same name and in same namespace but here it can't happen.
One more issue is that on version 1.0.0-preview4-004079 <OutputType>Exe</OutputType> is not considered and it is always generating DLL instead of exe.
@SamvelS I see. So you have:
/myproj
/myproj.csproj
/myinnerproj
/myinnerproj.csproj
Is that right? Then for the first issue, you should be able to modify your myproj.csproj's compile Items like this:
<Compile Include="**\*.cs" Exclude="bin\**;obj\**;myinnerproj\**.*" />
You may need to play with the glob a little, but this will allow the outer project to ignore the sources of the inner project.
RE the
For first one structure is correct. I will try DLL part with tomorrows build as well and will create a bug if will see it again. I tested on Windows and Mac OS.
@piotrpMSFT
So i just gave the migration code that parses the AssemblyInfo.cs a short test to try to reproduce my former issue.
The migration fails with the following attributes (using the full namespace and/or the "Attribute" suffix):
[assembly: System.Reflection.AssemblyCompany("fooo")]
[assembly: System.Reflection.AssemblyProduct("TestApp")]
[assembly: System.Reflection.AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersionAttribute("1.0.0.0")]
used dotnet version was 1.0.0-preview3-004056. I'll try with the latest preview4 in a few minutes (sloooow download here in austria).
Same with 1.0.0-preview4-004079. The migration issue can be worked around by adding the corresponding <Generate*Attribute>false</..>. Or by not being such a :trollface: and sticking to the templates and good code styling.
VSCode IntelliSense currently gives the ...Attribute version for completion in 1.5.0

Thanks for hunting down the root cause, @dasMulli
/cc @livarcocc
@piotrpMSFT I tried suggested solution with adding Exclude to Compile section and getting following crash:
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Build.Shared.FileMatcher.GetFiles(String projectDirectoryUnescaped, String filespecUnescaped, IEnumerable`1 excludeSpecsUnescaped, GetFileSystemEntries getFileSystemEntries, DirectoryExists directoryExists)
at Microsoft.Build.Internal.EngineFileUtilities.GetFileList(String directoryEscaped, String filespecEscaped, Boolean returnEscaped, IEnumerable`1 excludeSpecsEscaped)
at Microsoft.Build.Evaluation.LazyItemEvaluator`4.IncludeOperation.SelectItems(Builder listBuilder, ImmutableHashSet`1 globsToIgnore)
at Microsoft.Build.Evaluation.LazyItemEvaluator`4.LazyItemOperation.Apply(Builder listBuilder, ImmutableHashSet`1 globsToIgnore)
at Microsoft.Build.Evaluation.LazyItemEvaluator`4.MemoizedOperation.Apply(Builder listBuilder, ImmutableHashSet`1 globsToIgnore)
at Microsoft.Build.Evaluation.LazyItemEvaluator`4.LazyItemList.ComputeItems(LazyItemList lazyItemList, ImmutableHashSet`1 globsToIgnore)
at Microsoft.Build.Evaluation.LazyItemEvaluator`4.LazyItemList.GetItems(ImmutableHashSet`1 globsToIgnore)
at Microsoft.Build.Evaluation.LazyItemEvaluator`4.<>c.<GetAllItems>b__22_0(LazyItemList itemList)
at System.Linq.Enumerable.<SelectManyIterator>d__157`2.MoveNext()
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source, Int32& length)
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.OrderedEnumerable`1.ToList()
at Microsoft.Build.Evaluation.LazyItemEvaluator`4.GetAllItems()
at Microsoft.Build.Evaluation.Evaluator`4.Evaluate()
at Microsoft.Build.Execution.ProjectInstance.Initialize(ProjectRootElement xml, IDictionary`2 globalProperties, String explicitToolsVersion, String explicitSubToolsetVersion, Int32 visualStudioVersionFromSolution, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext buildEventContext)
at Microsoft.Build.Execution.ProjectInstance..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext buildEventContext)
at Microsoft.Build.BackEnd.RequestBuilder.LoadProjectIntoConfiguration()
at Microsoft.Build.BackEnd.RequestBuilder.<BuildProject>d__57.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.Build.BackEnd.RequestBuilder.<BuildAndReport>d__49.MoveNext()
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Build.CommandLine.MSBuildApp.BuildProject(String projectFile, String[] targets, String toolsVersion, Dictionary`2 globalProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, Int32 cpuCount, Boolean enableNodeReuse, TextWriter preprocessWriter, Boolean debugger, Boolean detailedSummary)
at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Build.CommandLine.MSBuildApp.BuildProject(String projectFile, String[] targets, String toolsVersion, Dictionary`2 globalProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, Int32 cpuCount, Boolean enableNodeReuse, TextWriter preprocessWriter, Boolean debugger, Boolean detailedSummary)
at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
at Microsoft.Build.CommandLine.MSBuildApp.Main(String[] args)
@SamvelS do you have a minimal repro you can share?
@piotrpMSFT sure, here is project https://dl.dropboxusercontent.com/u/65479031/folder.zip. When you try to restore, it gives error above.
Thanks for that! What a gnarly bug.
@cdmihai @rainersigwald @jeffkl can you guys take a look? NullRef in MSBuild!
Nasty indeed. I suspect the same root cause as https://github.com/Microsoft/msbuild/pull/1349.
@rainersigwald do you want this in MSBuild repo? We can't do much here in CLI so I'd like to close...
Yes, let's call Microsoft/msbuild#1349 the original and close this as a duplicate.
in my case, deleting Properties/AssemblyInfo.cs did the trick.
What happened to this property?
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
I just updated VS 2017 Preview today and I tried this property and it doesn't work. What's more I don't see it in the project file Intellisense list.