Why error "FS0239 an implementation of the file or module has already been given"? - visual-studio

Visual Studio is underlining the F# code in one of my source files with a red squiggly. The error message reads, "FS0239 an implementation of the file or module ________ has already been given."
When I search the Visual Studio Solution Explorer, there is only one file or module with the supposedly duplicate name.
What's going on?

I found that my *.fsproj file had several lines duplicated, like this:
<Compile Include="File1.fs" />
<Compile Include="File2.fs" />
<Compile Include="File3.fs" />
<Compile Include="File1.fs" />
<Compile Include="File2.fs" />
<Compile Include="File3.fs" />
Removing the duplicates fixed the problem.
As a side note, I think the duplication was caused by a Git merge.

Related

Conditional compilation new csproj and visual studio solution explorer

I have the following in my csproj file
<ItemGroup>
<Compile Remove="WebControls/**/*" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<Compile Remove="Lucene/**/*" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
</ItemGroup>
I'm not even sure if this is the right approach, I'm trying to avoid having to go through those files and add a conditional compilation symbol such as "#if NET462".
The problem is that those files disappear from the solution explorer when I add that to csproj, is there a way to switch the target platform to net462 in the solution explorer so that they show again?

Xamarin.Forms netstandard project broken with update to VS 2017.3

So today i made the mistake of updating my IDE to 2017.3.
I was then notified of incompatibilities such as
"NU1202: The package Xamarin.Forms 2.3.4.247 is not compatible with netstandard1.5. Package supports: list of targets such as monoandroid10, xamarinios10, etc"
After investigating the matter on google i found some information to try fix the project.
https://github.com/NancyFx/Nancy/issues/2647#issuecomment-265927440 suggests adding a frameworkmoniker to get it to build (At some point during fix attempts i had a platform warning too)
Another attempt i've made to fix the issue was recreating the project as a fresh template version of using a netstandard project (the project i've provided for repro was created during the time when project.json was still a thing)
You may ask why: While looking for the issue i read that some are false positive error messages, which can be disabled like this Package Reference Warning Ignore - However in this project type which is entirely based on .csproj again i was unable to add Xamarin.Forms 2.3.4.247.
So my question is:
Has anyone been able to get a similar project running on vs2017.3 yet?
REPRO project:
GitHub
After changing my project similar to a result of this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.5</TargetFramework>
<PackageTargetFallback>portable-net45+win8+wpa81+wp8</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="App.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="MainPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.Portable.Compatibility" Version="1.0.1" />
<PackageReference Include="Xamarin.Forms" Version="2.3.4.247" />
</ItemGroup>
<ItemGroup>
<Compile Update="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Update="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>
the project compiled again.
<PackageTargetFallback>portable-net45+win8+wpa81+wp8</PackageTargetFallback>
fixed the issue.

Cannot modify an evaluated object originating in an imported file

I am trying to delete a file from my visual studio project, but this dialogue pops up and prevent me from doing that. What does it mean and how do I resolve this problem?
There is a xamarin thread about this but no solution there.
https://forums.xamarin.com/discussion/25719/cannot-modify-an-evaluated-object-originating-in-an-imported-file
I ran across this question as well as a couple others related to the error message, specifically. My issue was different from the OP's as it had to do with NuGet packages not installing/uninstalling/updating.
I opened the .CSProj files only to see the package reference completely missing for Microsoft.NET.Test.Sdk, ie some VS file somewhere was caching this bad reference, even after killing all existing .vs directories. So I just added it manually, ran nuget restore, and was back in business.
Basically, I modified this block of project file XML:
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.8</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>1.4.0</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>1.4.0</Version>
</PackageReference>
</ItemGroup>
to this:
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.8</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>1.4.0</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>1.4.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>16.1.1</Version>
</PackageReference>
</ItemGroup>
Restarting Visual Studio fixed the issue for me.
We have no idea what the real problem is, but we do find a fix by comparing this project with some other project files that we have.
The fix is to open the .Shared.vcxitems file in an text editor and replace this:
<ItemGroup>
<ProjectCapability Include="$(MSBuildThisFileDirectory)SourceItemsFromImports" />
</ItemGroup>
with this
<ItemGroup>
<ProjectCapability Include="SourceItemsFromImports" />
</ItemGroup>
In my solution happend because there was NuGet packages source pointing to non-existent local folder, changed it in Package Manager Settings.
My workaround was to open the .vcxitems and .vcxitems.filters, mentioned in the error message, in text editor and delete the file directly in the xml. Also I want to note that this error appears for me only when I tried to delete files that were part of different .vcxitems that was imported into main project. You can check your main project for <Import Project="xyz.vcxitems" />.

Why is my cpp file not in the ClCompile index, causing LNK2019 and LNK2001 errors?

I was receiving LNK2019 and LNK2001 errors in VS 2010 but not with g++. I searched around looking for reasons but everything talked about making sure the right headers were included, the functions properly defined, etc.
After going to the project directory and opening the .vcxproj file I saw this list:
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="pilElem3.cpp" />
... many lines ...
<ClCompile Include="utlMatrixFull.cpp" />
<ClCompile Include="utlVector.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pilElem3.h" />
... many lines ...
<ClInclude Include="utlMatrixFull.h" />
<ClInclude Include="utlVector.h" />
</ItemGroup>
<ItemGroup>
<None Include="pilElement.cpp" />
</ItemGroup>
pilElement is the parent class to pilElem3 and pilElem4 which were having the linker error.
I didn't change any of the filters or alter the project since creating it.
a) Why did VS think this file should be ignored?
b) How could I notice this sooner?
In answer to how I suspect that you may have inadvertently right clicked on the file in the project explorer - all to easy to do in VS.
How to make sure it doesn't happen in the future you have 2 options a) Don't use visual studio or b) Use a revision control system such as Mercurial and include the project file in those you are controlling - and do regular commits - you will be able to revert changes to the project file if needed and you should notice if it is in the changed file list when you are not expecting it to have changed.

Visual Studio, csproj: How can I specify a linked file in DependentUpon?

Suppose I have a default.aspx.cs in my project, but I want to make it dependent upon the default.aspx file that's linked. E.g.:
<Content Include="..\somedir\default.aspx">
<Link>Default.aspx</Link>
</Content>
This doesn't work:
<Compile Include="default.aspx.cs">
<DependentUpon>Default.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
This also doesn't work:
<Compile Include="default.aspx.cs">
<DependentUpon>..\somedir\default.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
For both, I get this error:
The parent file, 'Default.aspx', for file 'default.aspx.cs' cannot be found in the project file.
Is it possible to have a file be dependent upon a linked file?
I tried the same thing and it seems is not supported. Check this: https://bitbucket.org/jfromaniello/nestin/issue/4/error-when-nesting-linked-files "DependentUpon does not work with linked files."

Resources