Targeting C++/CLI project to .Net 6.0 - Error : Project does not reference "native,Version=v0.0" framework - c++-cli

Am upgrading my WPF project to .Net 6 which internally refers C++/CLI project. So am trying to upgrade my C++ project also to .Net6.0.
Changed the below properties in .vcxproj
<CLRSupport>NetCore</CLRSupport>
<TargetFramework>net6.0-windows</TargetFramework>
While building the project, it fails with the below error.
Your project does not reference "native,Version=v0.0" framework. Add a reference to "native,Version=v0.0" in the "TargetFrameworks" property of your project file and then re-run NuGet restore.
Anyone please guide me on - referring a C++ project (.Net Framework 4.6) in .Net 6.0
Do we need to upgrade c++ library to .Net 6.0 to consume it in .Net6.0 apps
How can we add reference to “native, Version0.0” in TargetFrameworks

When I made my project changes to get a C++/CLI-based assembly to build using .NET 6, I had the CLRSupport and TargetFramework changes like you show. But, I also had to change the <ItemGroup> containing the Reference elements to instead use a single <FrameworkReference> element. Note that my code called into WPF so there's a lot of those assemblies there.
Old:
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
New:
<ItemGroup>
<FrameworkReference Include="Microsoft.WindowsDesktop.App" />
</ItemGroup>

Related

Could not find System.Object VB.NET

Error : Fody: Could not find 'System.Object'. WindowsApp1
hi, something called Fody, it embed dlls assembly into project.
problem is it work only with C# |and i need use it as VB, i cant reduce Netframwork less than 4.6 cause dll's required high netframwork.
error only occurs when running Fody on a VB assembly using the full .Net Framework
so they say it can be solve By
try adding explicit references to your VB project
<Reference Include="mscorlib" />
<Reference Include="System" />
how can do it, because not automatically included in VB projects
Go to your Project file
edit vbproj
you can find <Reference Include="System" />
add before it <Reference Include="mscorlib" />

ASP.NET Core 2.0 InvalidOperationException: Cannot find compilation library location for package '<assemblyname>'

I have an ASP.NET Core 2.0 Razor Pages project. I am using Visual Studio 2017.
I have added one of our in-house assemblies to the project (it contains common definitions, types and functions etc). The project compiles but when I attempt to run it I get the following error.
Here is my .csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<Version>2018.3.12.6</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JWT" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="dotnet-setversion" Version="*" />
</ItemGroup>
<ItemGroup>
<Reference Include="Common">
<HintPath>..\packages\Common.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
Here's my Visual Studio 2017 project showing the assembly in the project.
Googling the error doesn't provide much useful information.
How do I add a reference to a custom assembly in an ASP.NET Core 2.0 Razor Pages project?
I fixed the same issue by installing Microsoft.Extensions.DependencyModel, version 2.0.3.
The solution to the problem has been posted here https://github.com/dotnet/core-setup/issues/2981
See the top comment (by tuespetre) and then the update just further down (also by tuespetre). This worked for me.

.NET Core 1.1 - getting "Duplicate 'Content' items were included"

I've updated my VS2017 to latest 15.3.0 and installed .NET Core SDK 2.0 (I would like to upgrade an existing .NET 1.1 application to 2.0).
Now when I open my project that was compiling fine (didn't change anything in it yet) and I try to compile I get:
Duplicate 'Content' items were included.
The .NET SDK includes 'Content' items from your project directory by default.
You can either remove these items from your project file, or set the 'EnableDefaultContentItems' property to 'false' if you want to explicitly include them in your project file.
For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'wwwroot\index.html'
Under problematic file it's pointing to C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets
I've read online and I'm able to solve this by adding <EnableDefaultContentItems>false</EnableDefaultContentItems> to my .csproj file. But it wasn't there before and I'm not sure what adding this line means.
Once thing that really bothers me is that the source file it's pointing to is in dotnet\sdk\2.0.0 - and as I mentioned the project is still .NET Core 1.1. All I did so far was to install the update for VS2017 and the 2.0 SDK.
How do I solve this? I would like my original project to compile before I upgrade it to 2.0.
EDIT
My csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Content Include="wwwroot\index.html" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4" Version="1.5.2" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.4.1" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="web.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
As mentioned if I add <EnableDefaultContentItems>false</EnableDefaultContentItems> to PropertyGroup it works. But I don't know what is the meaning of this or why it's needed all of a sudden...
Remove the <ItemGroup> element containing
<Content Include="wwwroot\index.html" />
This item is already included by the Microsoft.NET.Sdk.Web and is therefore defined twice.
Necromancing.
Alternatively, do the following:
Click 'Show All Files' in Solution Explorer
Right click over 'wwwroot' select 'Exclude From Project'
Right click over 'wwwroot' select 'Include in Project'
The error is now gone.
Much safer than editing by hand.

Installed NuGet package, Visual Studio claims assembly not referenced

you can see that I have referenced it through nuget, but is still complaining. This is in a .net 4.6.1 framework class library in an embedded view component.
I'm also using a .net framework asp.net core web app.
I'm having a bunch of issues trying to get razor to work, but this one is a new one. MenuViewPage inherits RazorPage and is located in another assembly.
I think I should just install .net core 2, and aspnetcore.all ;)\
Anyone have any ideas why this is happening?
So after hours of trying to sort this issue out I've come to a solution:
When creating a web class library, whether you are using it for application parts or you are creating your core project with base classes I advise you covert it from a normal .net class library to a web enabled one.
To convert it to a web class library you need to change the project to use the following .csproj, then make sure to run dotnet restore.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
<PreserveCompilationContext>true</PreserveCompilationContext>
<ApplicationIcon />
<OutputTypeEx>library</OutputTypeEx>
<StartupObject />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile></DocumentationFile>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Razor">
<Version>1.1.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Razor.Runtime">
<Version>1.1.2</Version>
</PackageReference>
<PackageReference Include="System.Net.Http" Version="4.3.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>
</Project>
Make sure you are making the output type a library.
I ran into issues with the assembly info file, it seems to be generated during build now, so I commented out the assembly.info stuff by double clicking "Properties"
I hope this helps someone in the future.

Relative Referencing in Visual Studio 2013 (vb.net)

Problem: So, my issue is that I have 3 .dll files I want to include in my software. However, whenever I transfer the .exe to another computer, it looks for my hard coded absolute path in my computer. I want the dlls to be included or embedded such that I can distribute it to others.
Setup:
I have done so by going to the solution explorer and doing Add->Exisiting Item, and add the three dlls into the solution explorer.
Then I went to each .dll's properties and changed them so that they are considered embedded resources. Like so:
Then I went to the references tab of the project property, and added a reference to the three dlls in my code. I originally had them in my /bin/ folder of my project, but I still had this problem. so I added them here in the same folder as my project.
Great, so I compile, copy to another computer, and get an exception (I threw it to a message box for ease) saying it can't find the dll and/or its dependencies. I even put a copy of the dll in the same .exe folder on the separate computer, but the same problem.
What I've Tried: So I tried messing around with the project file. But it looked ok to me. Here's a snippet:
<ItemGroup>
<Reference Include="PcapDotNet.Base, Version=0.10.0.20588, Culture=neutral, PublicKeyToken=4b6f3e583145a652, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\PcapDotNet.Base.dll</HintPath>
</Reference>
<Reference Include="PcapDotNet.Core, Version=0.10.0.20632, Culture=neutral, PublicKeyToken=4b6f3e583145a652, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\PcapDotNet.Core.dll</HintPath>
</Reference>
<Reference Include="PcapDotNet.Packets, Version=0.10.0.20603, Culture=neutral, PublicKeyToken=4b6f3e583145a652, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\PcapDotNet.Packets.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
and later ...
<ItemGroup>
<EmbeddedResource Include="PcapDotNet.Base.dll" />
<EmbeddedResource Include="PcapDotNet.Core.dll" />
<EmbeddedResource Include="PcapDotNet.Packets.dll" />
</ItemGroup>
Question: So, why is it saying it can't find the dll? Where could it still be looking for it in the wrong place?
Thanks everyone!
Thanks for the help guys! I found the solution was a problem with Pcap dot net (pcap.net). The issue was that the supporting computer didn't have the Microsoft Redistributable C++ package. It says that is needed on their website. I thought that was for development only, but turns out it is needed for running as well. I might try to include those dll's in the embedded resources as well to clean it up for the user.