Embedded library in multi targeting .NET project - c#

I have a .NET project that has 2 target frameworks: netstandard1.6 and net40. I am trying to embedded a libraries (ICU4N and J2N) that has target on netstandard1.3 and net40.
I created a ...\lib\ folder where I put .dll libraries for the corresponding targets.
My .csprog file looks like this
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup Label="Configuration">
<SignAssembly>True</SignAssembly>
<DelaySign>False</DelaySign>
<DocumentationFile>$(TargetDir)bin\$(Configuration)\$(TargetFramework)\someName.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netstandard1.6;net40</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<OutputType>library</OutputType>
</PropertyGroup>
...
<PropertyGroup>
<NoWarn>1701;1702;1591;1570;1572;1573;1574;1580;1584;1658</NoWarn>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
<Reference Include="System" />
</ItemGroup>
...
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
<PackageReference Include="Microsoft.NETCore.Portable.Compatibility" Version="1.0.1" />
<Reference Include="ICU4N, Version=60.0.0.0, Culture=neutral, PublicKeyToken=efb17c8e4f0e291b">
<HintPath>lib\ICU4N\netstandard1.3\ICU4N.dll</HintPath>
</Reference>
<Reference Include="J2N, Version=2.0.0.0, Culture=neutral, PublicKeyToken=f39447d697a969af">
<HintPath>lib\J2N\netstandard1.3\J2N.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
<Reference Include="ICU4N, Version=60.0.0.0, Culture=neutral, PublicKeyToken=efb17c8e4f0e291b">
<HintPath>lib\ICU4N\net40\ICU4N.dll</HintPath>
</Reference>
<Reference Include="J2N, Version=2.0.0.0, Culture=neutral, PublicKeyToken=f39447d697a969af">
<HintPath>lib\J2N\net40\J2N.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
When I run the program,
System.IO.FileNotFoundException : Could not load file or assembly
'System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.
error is issued, this error appears due to the fact that files ...\bin\Debug\net40\ICU4N.dll and ...\bin\Debug\netstandard1.6\ICU4N.dll are the same, but should be different.
The question is how to configure the project and .csproj file so that during build the version of the netstandard1.3 library falls into the folder ...\bin\Debug\netstandard1.6\, and net40 version of the library into folder ...\bin\Debug\net40\, because now the net40 version of the library falls into folder ...\bin\Debug\netstandard1.6\ and ...\bin\Debug\net40\.
Thank you in advance.

The problem is in HintPath, the first found library was embedded.
Decision:
Add the following code for netstanard1.6 target block.
<None Remove="lib\ICU4N\net40\ICU4N.dll" />
<None Remove="lib\J2N\net40\J2N.dll" />

Related

Migrating to .csproj SDK breaks import of dlls from nuget package

Recently I tried to upgrade my .csproj files to SDK standard using .net upgrade assistant. Initially it seems to work and all my nuget dependencies came along for the ride.
However when I try to build my project (targeting .net48) the dlls from the nuget package are not included in the output directory. I've been looking for solutions around the web, but most of them seem to indicate that they should be present. The specific package I'm having problems with is RavenDB.Database v2.5.25041. It is part of a test suite that needs this specific version so I cannot unfortunately upgrade it. The tests also do not run and complain about missing assemblies unless the dlls are present in the output directory (testet by manually copying them).
Running a build on the project before the SDK-migration works fine and the output directory includes those dlls. Does anyone know why this work differently in the new version and how can I resolve it?
Edit:
This is the .csproj file after conversion:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Data.Services.Client" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.4.4" />
<PackageReference Include="RavenDB.Database" Version="2.5.25041" />
<PackageReference Include="RavenDB.Embedded" Version="2.5.25041" />
</ItemGroup>
</Project>
Edit2:
The .csproj file before conversion (warning, big):
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\EntityFramework.6.4.4\build\EntityFramework.props" Condition="Exists('..\..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" />
<Import Project="..\..\packages\JunitXml.TestLogger.2.1.81\build\net45\JUnitXml.TestLogger.props" Condition="Exists('..\..\packages\JunitXml.TestLogger.2.1.81\build\net45\JUnitXml.TestLogger.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7A3590CE-A43F-4A69-B520-27402FDD9F87}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sti.TestUtils</RootNamespace>
<AssemblyName>Sti.TestUtils</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.Edm, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Data.Edm.5.2.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.OData, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Data.OData.5.2.0\lib\net40\Microsoft.Data.OData.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\WindowsAzure.Storage.2.0.0.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
</Reference>
<Reference Include="Raven.Abstractions, Version=2.5.0.0, Culture=neutral, PublicKeyToken=37f41c7f99471593, processorArchitecture=MSIL">
<HintPath>..\..\packages\RavenDB.Client.2.5.25041\lib\net45\Raven.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Raven.Client.Embedded, Version=2.5.0.0, Culture=neutral, PublicKeyToken=37f41c7f99471593, processorArchitecture=MSIL">
<HintPath>..\..\packages\RavenDB.Embedded.2.5.25041\lib\net45\Raven.Client.Embedded.dll</HintPath>
</Reference>
<Reference Include="Raven.Client.Lightweight, Version=2.5.0.0, Culture=neutral, PublicKeyToken=37f41c7f99471593, processorArchitecture=MSIL">
<HintPath>..\..\packages\RavenDB.Client.2.5.25041\lib\net45\Raven.Client.Lightweight.dll</HintPath>
</Reference>
<Reference Include="Raven.Database, Version=2.5.0.0, Culture=neutral, PublicKeyToken=37f41c7f99471593, processorArchitecture=MSIL">
<HintPath>..\..\packages\RavenDB.Database.2.5.25041\lib\net45\Raven.Database.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Services.Client" />
<Reference Include="System.Spatial, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Spatial.5.2.0\lib\net40\System.Spatial.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\JunitXml.TestLogger.2.1.81\build\net45\JUnitXml.TestLogger.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\JunitXml.TestLogger.2.1.81\build\net45\JUnitXml.TestLogger.props'))" />
<Error Condition="!Exists('..\..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
<Error Condition="!Exists('..\..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
</Target>
<Import Project="..\..\packages\EntityFramework.6.4.4\build\EntityFramework.targets" Condition="Exists('..\..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" />
</Project>
I managed to find a workaround for this specific case. Since the dlls are downloaded as part of the nuget package you can force dotnet to include them in the build output by adding the following to the .csproj file of the final assembly. Meaning the assembly that is actually built to an executable.
Add the package reference and set GeneratePathProperty to true.
<PackageReference Include="RavenDB.Database" Version="2.5.25041">
<GeneratePathProperty>True</GeneratePathProperty>
</PackageReference>
Then reference the missing dlls using the generated path property.
<ItemGroup>
<Reference Include="Esent.Interop">
<HintPath>$(PkgRavenDB_Database)\lib\net45\Esent.Interop.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.NRefactory">
<HintPath>$(PkgRavenDB_Database)\lib\net45\ICSharpCode.NRefactory.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.NRefactory.CSharp">
<HintPath>$(PkgRavenDB_Database)\lib\net45\ICSharpCode.NRefactory.CSharp.dll</HintPath>
</Reference>
<Reference Include="Lucene.Net">
<HintPath>$(PkgRavenDB_Database)\lib\net45\Lucene.Net.dll</HintPath>
</Reference>
<Reference Include="Lucene.Net.Contrib.Spatial.NTS">
<HintPath>$(PkgRavenDB_Database)\lib\net45\Lucene.Net.Contrib.Spatial.NTS.dll</HintPath>
</Reference>
<Reference Include="Spatial4n.Core.NTS">
<HintPath>$(PkgRavenDB_Database)\lib\net45\Spatial4n.Core.NTS.dll</HintPath>
</Reference>
This will point the build tools to the dlls regardless of where it saves downloaded nuget packages.
Read more about GeneratePathProperty on msdocs
You are building a library project. It is normal for full output resolution of transitive packages not to happen when building a library, because until an application project exists, it doesn't know the full story. Some of your transitive packages might have different outputs for different platforms; the application chooses the target platform, not any of the libraries.
Add an application project (just a console exe would do) that references your library as a project-reference, and look at the output folder of that. If your test project isn't working: check that your test project is using a project or package reference to your library, and not a dll reference to your library's output.
If there are specific things that still don't work, check whether there are package available for some of the many omitted references in the translation that might not be needed for build, but might actually still be needed at runtime.
This is expected behaviour - see https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore#restore-packages, in particular:
After a successful restore:
For projects that use <PackageReference>, the package is present in the local global-packages folder, and the project
obj/project.assets.json file is recreated.
For projects that use packages.config, the package appears in the project's packages folder.
The project should now build successfully.
By switching to PackageReference, you've changed the behaviour of the restore to the more modern setup where packages are consumed from a global cache (typically %userprofile%\.nuget\packages)

Github action nuget restore .NET 4.7.2

I have a .net framework C# project targetting .net 4.7.2 and I'm trying to do a nuget restore and build using a github action.
I'm getting the following error on nuget restore:
Run nuget restore SAPtoAPLv3Check/SAPtoAPLv3Check.csproj
MSBuild auto-detection: using msbuild version '16.11.0.36601' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin'.
Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.
Error: Process completed with exit code 1.
My github action looks like this:
name: Release
on:
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code.
uses: actions/checkout#v2
- name: Setup .NET
uses: actions/setup-dotnet#v1
with:
dotnet-version: 5.0.x
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild#v1.0.2
- name: Setup Nuget
uses: Nuget/setup-nuget#v1.0.5
- name: Restore nuget packages
run: nuget restore SAPtoAPLv3Check/SAPtoAPLv3Check.csproj
- name: Build
run: msbuild SAPtoAPLv3Check/SAPtoAPLv3Check.csproj /p:Configuration=Release
I have other github actions building later .net framework versions, and restoring nugets, fine. Mainly those targeting .netcore and .net48x.
Where I should specify the folder for nuget?
nuget restore -OutputDirectory "????" SAPtoAPLv3Check/SAPtoAPLv3Check.csproj
My .csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BF3CB6D2-503F-4ED9-96E6-6D5DD50EA201}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SAPtoAPLv3Check</RootNamespace>
<AssemblyName>SAPtoAPLv3Check</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Dapper.2.0.90\lib\net461\Dapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c">
<HintPath>..\packages\NLog.5.0.0-preview.1\lib\net46\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SentilanAgent.MessageV1, Version=1.2.7912.29046, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\SentilanAgent.MessageV1.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QueryRow.cs" />
<Compile Include="ServerAndDatabase.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="databases.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Lib\SentilanAgent.MessageV1.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
What I don't have is a packages.config, is this what I'm missing. Adding the nugets via Rider didn't generate one.
I pointed the nuget restore at the .sln file rather than the .csproj and it worked.

error MSB3644: The reference assemblies for framework ".NETFramework,Version=v3.5" were not found - ubuntu

I'm running a dotnet build command on a legacy project originally created by someone else I don't know, under Windows some many years ago, but on my Linux Ubuntu 16.04 laptop it gives me the error:
/home/stephane/programs/dotnet-sdk-2.2.204-linux-x64/sdk/2.2.204/Microsoft.Common.CurrentVersion.targets(1183,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v3.5" were not found.
I downloaded and installed the dotnet SDK yesterday, with the dotnet-sdk-2.2.204-linux-x64 archive, and the configuration info is:
$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.2.204
Commit: 8757db13ec
Runtime Environment:
OS Name: ubuntu
OS Version: 16.04
OS Platform: Linux
RID: ubuntu.16.04-x64
Base Path: /home/stephane/programs/dotnet-sdk-2.2.204-linux-x64/sdk/2.2.204/
Host (useful for support):
Version: 2.2.5
Commit: 0a3c9209c0
.NET Core SDKs installed:
2.2.204 [/home/stephane/programs/dotnet-sdk-2.2.204-linux-x64/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.5 [/home/stephane/programs/dotnet-sdk-2.2.204-linux-x64/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.5 [/home/stephane/programs/dotnet-sdk-2.2.204-linux-x64/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.5 [/home/stephane/programs/dotnet-sdk-2.2.204-linux-x64/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
And the .csproj file contains:
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{1F89C6A7-BCC7-4B9A-AF06-4BA515541489}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<RootNamespace>RoseauWin</RootNamespace>
<AssemblyName>RoseauWin</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Reference Include="Sanford.Multimedia">
<HintPath>..\Sanford.Multimedia.Midi\bin\Debug\Sanford.Multimedia.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainForm.cs" />
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Roseau.ComponentModel\Roseau.ComponentModel.csproj">
<Project>{28F134E7-F044-4153-A8AE-0C18E6351635}</Project>
<Name>Roseau.ComponentModel</Name>
</ProjectReference>
<ProjectReference Include="..\Roseau.Music.Generators\Roseau.Music.Generators.csproj">
<Project>{DBE17471-321A-400D-97A9-ADCEBFE960EA}</Project>
<Name>Roseau.Music.Generators</Name>
</ProjectReference>
<ProjectReference Include="..\Roseau.Music.Midi\Roseau.Music.Midi.csproj">
<Project>{FF7B26FF-AB13-4FCC-AC85-9FD04C2D0F1A}</Project>
<Name>Roseau.Music.Midi</Name>
</ProjectReference>
<ProjectReference Include="..\Roseau.Music\Roseau.Music.csproj">
<Project>{9A4CF19C-B0A7-4D74-8B01-C479FE8C3019}</Project>
<Name>Roseau.Music</Name>
</ProjectReference>
<ProjectReference Include="..\Roseau.Probability\Roseau.Probability.csproj">
<Project>{CA266A83-CB09-4A37-9160-0E67B7035C9C}</Project>
<Name>Roseau.Probability</Name>
</ProjectReference>
<ProjectReference Include="..\Roseau.Windows.Forms\Roseau.Windows.Forms.csproj">
<Project>{CCAC8FF9-E2BD-4B76-B479-72D91D1170BD}</Project>
<Name>Roseau.Windows.Forms</Name>
</ProjectReference>
<ProjectReference Include="..\Sanford.Multimedia.Midi\Sanford.Multimedia.Midi.csproj">
<Project>{4269C72A-8D3A-4737-8F89-72EAA33EA9E1}</Project>
<Name>Sanford.Multimedia.Midi</Name>
</ProjectReference>
</ItemGroup>
</Project>
Is this above file a build file ? An equivalent to a pom.xml file in a Maven Java application ?
I never touched a .Net application before.
What is this ToolsVersion="3.5" and <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> ?
Can I edit this file ? What version can I change ?
I've seen this page and I hope I won't have to acquire so much knowledge just to build it. After all, I'm rewritting this application from scratch in Java and Typescript.

'This is the 'bait'. You probably need to add one of the SQLitePCLRaw.bundle_* nuget packages

I am using Entity Framework Core 2 in my application using SQLite as my database provider.
I have added references to the following in my project:
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Sqlite.Core
Microsoft.Data.Sqlite
SQLitePCLRaw.batteries_green
SQLitePCLRaw.batteries_v2
SQLitePCLRaw.core
SQLitePCLRaw.provider.e_sqlite3
I am trying to use the IMigrator on my dbcontext to setup my initial database like so:
using (var dbContext = new DbContext())
{
var migrator = dbContext.GetInfrastructure().GetRequiredService<IMigrator>();
migrator.Migrate();
}
In my DbContext I am setting adding the service with:
options.UseSqlite(connectionString);
My connection string is just a local path.
This all seems like what I should be doing as per Microsoft's documentation. However when I try to run my application, I get the following error:
'This is the 'bait'. You probably need to add one of the
SQLitePCLRaw.bundle_* nuget packages to your platform project.'
As far as I'm aware I have added a SQLitePCLRaw.bundle_* package since I am referencing both SQLitePCLRaw.batteries_green and SQLitePCLRaw.batteries_v2.
Does anyone know of a way to fix this error and use SQLite as my database provider?
Edit
My Data project .csproj (slightly redacted):
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EA5DB634-7838-4C96-8DF5-4051B31DFFD2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Data</RootNamespace>
<AssemblyName>Data</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Build\Debug\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\Build\Release\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\Build\Debug\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>..\Build\Release\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Data.Sqlite">
<HintPath>..\References\Microsoft.Data.Sqlite.Core.2.0.0\lib\netstandard2.0\Microsoft.Data.Sqlite.dll</HintPath>
</Reference>
<Reference Include="Microsoft.EntityFrameworkCore">
<HintPath>..\References\Microsoft.EntityFrameworkCore.2.0.0\lib\netstandard2.0\Microsoft.EntityFrameworkCore.dll</HintPath>
</Reference>
<Reference Include="Microsoft.EntityFrameworkCore.Relational">
<HintPath>..\References\Microsoft.EntityFrameworkCore.Relational.2.0.0\lib\netstandard2.0\Microsoft.EntityFrameworkCore.Relational.dll</HintPath>
</Reference>
<Reference Include="Microsoft.EntityFrameworkCore.Sqlite.Core">
<HintPath>..\References\Microsoft.EntityFrameworkCore.Sqlite.Core.2.0.0\lib\netstandard2.0\Microsoft.EntityFrameworkCore.Sqlite.dll</HintPath>
</Reference>
<Reference Include="Microsoft.EntityFrameworkCore.SqlServer">
<HintPath>..\References\Microsoft.EntityFrameworkCore.SqlServer.2.0.0\lib\netstandard2.0\Microsoft.EntityFrameworkCore.SqlServer.dll</HintPath>
</Reference>
<Reference Include="SQLitePCLRaw.batteries_green, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a84b7dcfb1391f7f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\SQLitePCLRaw.bundle_green.1.1.7\lib\net45\SQLitePCLRaw.batteries_green.dll</HintPath>
</Reference>
<Reference Include="SQLitePCLRaw.batteries_v2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8226ea5df37bcae9, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\SQLitePCLRaw.bundle_green.1.1.7\lib\net45\SQLitePCLRaw.batteries_v2.dll</HintPath>
</Reference>
<Reference Include="SQLitePCLRaw.core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1488e028ca7ab535, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\SQLitePCLRaw.core.1.1.7\lib\net45\SQLitePCLRaw.core.dll</HintPath>
</Reference>
<Reference Include="SQLitePCLRaw.provider.e_sqlite3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9c301db686d0bd12, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\SQLitePCLRaw.provider.e_sqlite3.net45.1.1.7\lib\net45\SQLitePCLRaw.provider.e_sqlite3.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\System.Collections.Immutable.1.4.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Annotations">
<HintPath>..\References\System.ComponentModel.Annotations.4.4.0\lib\netstandard2.0\System.ComponentModel.Annotations.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite, Version=1.0.104.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\System.Data.SQLite.1.0.104.0\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Interactive.Async, Version=3.1.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\System.Interactive.Async.3.1.1\lib\netstandard1.3\System.Interactive.Async.dll</HintPath>
</Reference>
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Sqlite\SqliteDbConnectionFactory.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
My DbContext is in a different project that references my Data project. The SqliteDbConnectionFactory sets up the UseSqlite on the DbContextOptionsBuilder from an OnConfiguring override in my DbContext.
So with judicious use of a decompiler, it turns out the NetStandard1.1 built SQLitePCLRaw.batteries_v2.dll assembly has the bait exception baked into it at compile time, while the net45 version correctly calls the SQLite provider initialiser.
I had been using the NetStandard assemblies at first since all the new Entity Framework and AspNetcore assemblies use some flavour of NetStandard so when I changed to net45 to test different configurations I neglected to delete by bin folder and so was getting conflicts with the different versions.
Clearing out the bin folder and only referencing net45 versions of the SQLitePCLRaw assemblies allowed the provider to be initialised.
The next error I ran into was that e_sqlite.dll could not be found. This is an un-managed assembly found in one of the SQLitePCLRaw.lib.e_sqlite3.* NuGet packages. I downloaded the SQLitePCLRaw.lib.e_sqlite3.v110_xp package and added e_sqlite.dll as a resource into my project which is copied into my bin directory at runtime.
Once I had the e_sqlite.dll in my bin, my project started successfully and created my database.

VSCode c# add reference to custom assembly

in Visual Studio Code I simply want to add a reference
to an custom c# assembly like
"../libs/mylib.dll"
how can I add this dependency?
I tried to add the path to the dependency but was not able to compile because its just wrong :)
"dependencies": {
"myassembly" : "../libs/Common.dll"
},
or
"dependencies": {
"log4net" : { "assembly":"../libs/log4net.dll" }
},
simpler, just add the following:
1) modify the myproject.csproj file
<ItemGroup>
<Reference Include="DllComunVb2008">
<HintPath>..\Dlls\DllComunVb2008.dll</HintPath>
</Reference>
</ItemGroup>
2) Add the using of the library you are going to use. Example: using Dllcomun;
I finally found a way to reference any .net assembly within visual studio code.
First to note: I only need the vscode for the intellisense. I will not compile the assembly in vscode /.netcore.
When I'm done with coding, I will use commandline-tools to generate my assembly.
And this is my solution:
Create an regular .net class library with Visual studio (not code)
This will create an myproject.csproj-file (wich can be read by vscode).
Or use my test.csproj-file at the bottom of the post.
create an folder for the referenced assemblies. I've just created an libs-directory inside the top-directory.
close vs and open the folder with vscode.
modify the *.csproj-file as followed:
note: we've created the project in debug-mode, so we can remove the release-property-group:
4.2. remove the Release-PropertyGroup (you don't have to, but you don't need it)
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
4.3. Modify the bin-output-path to the libs-directory
from
<OutputPath>bin\Debug\</OutputPath>
to
<OutputPath>libs</OutputPath>
4.4. put your referencing .net assembly (external or custom) in the libs-directory and references them like:
...
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<SpecificVersion>False</SpecificVersion>
<HintPath>log4net.dll</HintPath>
</Reference>
...
</ItemGroup>
...
this is the complete *.csproj file with reference to an log4net.dll.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{75278D05-4850-4282-8AB4-3643A9E799FF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Test</RootNamespace>
<AssemblyName>Test</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>libs</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<SpecificVersion>False</SpecificVersion>
<HintPath>log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="myassembly.cs" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
I create a project with dotnet and then open it with Visual Studio 2019. Then click project, Add reference, browse to Dll, then save project (save a solution incase you want to open it again with file)
Now open it with vscode.

Categories

Resources