Forum Visual Studio

Double reference to cs file ignored by Xamarin Studio on a Mac

dlpopescuCAdlpopescuCA USMember ✭✭
edited December 2016 in Visual Studio


I've just ran into an issue where a cs file appeared twice in the Sources, in the csproj file, but Xamarin Studio on a Mac simply ignored it.
After pulling the code onto my Windows machine, as soon as I tried to compile in Visual Studio, it complained about it.

Has anyone else ran into this issue or was it, maybe, just a freestyler random bug?



  • mattwardmattward GBMember Xamurai

    Is there a way to reproduce this?

    The screenshot looks like there is a C# file with the same name in two different folders. So I am assuming you were expecting a compiler error if the file contents were the same.

    I ran a simple test creating a C# library project, created another MyClass.cs file and added it to the Properties folder, then copied the code from the existing MyClass.cs into the new one, then built the solution and I saw a build error as expected.

  • dlpopescuCAdlpopescuCA USMember ✭✭
    edited December 2016

    Thank you, @mattward , for the quick reply.

    Well, I've just done a test on a Mac machine (see screenshot csproj file):

    • open up the csproj file in Atom,
    • duplicate a line in the ItemGroup node
    • try to compile.

    All that Xamarin Studio gives is this warning "Source file `User/Target.cs' specified multiple times (CS2002) ({project_name})"


  • mattwardmattward GBMember Xamurai

    This is a difference in behaviour between Mono's xbuild and Microsoft's MSBuild.

    If you build the project using MSBuild on Mono you should get an error. However the MSBuild support on Mono is still in preview.

    So a workaround is to use MSBuild which you can enable in Xamarin Studio's preferences - Projects - Build - Build with MSBuild. Or another workaround would be to enable Treat warnings as errors in the project options - Build - Compiler. For now you may want to stick with xbuild since MSBuild support is still experimental.

  • dlpopescuCAdlpopescuCA USMember ✭✭

    Thank you, @mattward ! I'll stick with xbuild, in that case. As for treating warnings as errors, I'd rather not do it, but thanks for the suggestion.


Sign In or Register to comment.