I am working on an ASP.Net core 2.1 web app project. I have 1 project in my solution and 3 other libraries, it's and advanced architecture (data access layer (DAL), business layer (BL), common layer (CL)), so i need to add references to connect some libraries and project. I have added CL reference to my project and to libraries DAL and BL. Now I have to add reference BL to my project, but when I add I get this type of error:
Version conflict detected fr Microsoft.EntityFrameworkCore/ Install/reference Microsoft.EntityFrameworkCore 2.2.1 directly to project 'WEB' to resolve this issue
When I am trying to install that version it says
Package restore failed. Rolling back package changes for 'WEB'
I can also mention that when I add reference BL to my project, it also includes DAL, and CL itself, (and DAL contains Microsoft.EntityFrameworkCore (2.2.1), can't understand what's the problem, any ideas?
Additional Images of the problem in here.
project.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CL\CL.csproj" />
</ItemGroup>
</Project>
i have added CL reference as you can see, now i want to add BL reference and get this error
The issue is because you're having local directory path to one of your {projectName}.csproj file
Kindly review your .csproj files by Right clicking project and select Edit {projectName}.scproj
e.g
<Reference Include="Microsoft.EntityFrameworkCore">
<HintPath>..\..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\Microsoft.EntityFrameworkCore\2.1.1\lib\netstandard2.0\Microsoft.EntityFrameworkCore.dll</HintPath>
</Reference>
If yes than go to Nuget Package Manager and add your library bu selecting nuget.org as Package Source
after restoring from nuget Package manager csproject file will have following tag Added
to
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.1.1" />
Here {projectName} is the name of C# project.
Just want to chip in that i had the same issue but with EntityFrameworkCore 3.0 preview. I solved it by simply downgrading all entityframework 3.0(preview) nuget packages to latest stable (2.2).
Hopefully this helps someone aswell, took me hours...
Option 1 check visual studio error window and identify which package is making the conflict .
make sure both packages have save version code
Related
Please I have a problem. sorry if question title are not recognized well, I can't upload full-image during my reputations.
Edit:
I need something like that maybe
https://github.com/RicoSuter/NuGetReferenceSwitcher
or
https://github.com/0UserName/NuGetSwitcher
but above repos are not updated to VS 2022? please any help?
Edit: Looks like other people asks about that issue: https://github.com/dotnet/sdk/issues/1151
Shortly, I need to make a Class Library project can modify/edit in my side only. Other people only use DLL reference or Nuget package.
What I need to do?
I need to create a main project that used across me as public source and other people as DLL only not debuggable.
In my side the class library project must seen if I choose MSBuild configuration (Debug mode) not Nuget DLL. but I need to modify whole core source. Then republish it again as Nuget to allow other people to use it privately.
I guess the whole gape in main project .csproj file. I need to modify it to allow Configuration to switch between Nuget build that visible to other developers and Debug that only visible at me. When choose it the <ProjectReference> should load and should become visible at my solution.
You can ignore Github things I mentioned. A repo can be private/public wihtout problem.
Problem Short Description:
I have main project in solution A. (Must be GIT public for other people)
I have class library in solution B (Which maybe used in 2 main projects) (Must be GIT private repo for me only)
I need the class library source only visible for me not other people. they just see Package or DLL.
The main project are public Git repo, while class library are private Git repo.
In my case I need to setup a 2 types of MSBuild configuration. (Debug/) and (Nuget/ )
the other people only allowed to use which are private nuget package and they must not debug the class library.
I need only me to use (Debug/<ProjectReference>) -> So I can change class library directly and build Nuget package for other people without PDB file,etc included.
What I try to do? What topics I read?
I Following topics I follow: Use local source code of NuGet package to debug and edit code (#Mr Qian comment)
and https://sitecore.stackexchange.com/questions/15293/what-are-packagereferences-and-how-will-they-help-optimise-the-way-i-deal-with-n/15294
I create two solutions. First (FooProject Executable), Second(FooClassLibrary)
I modify the FooProject.csproj and add following lines
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<ProjectReference
Include="..\..\FooClassLibrary\FooClassLibrary\FooClassLibrary.csproj">
<Project>{a2329af5-316e-4339-8b56-d78aba72e919}</Project>
<Name>FooClassLibrary</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<Reference Include="FooClassLibrary">
<HintPath>..\..\FooClassLibrary\FooClassLibrary\bin\Release\FooClassLibrary.dll>
</HintPath>
</Reference>
</ItemGroup>
Edit:
I fix issues in above .csproj code. Now class library referenced with two MSBuild configuration (Debug and Release). But I don't add Class Libray in FooProject solution in Debug MSBuild.
Should now I create two solutions *.sln files? one for FooProject and reference with FooClassLibrary as DLL for non-modifying debugging?
And second FooProject solution (FooClassDebuggingAndEdit.sln) that reference project to FooProject?
Here's a two solutions *.rar link
https://anonfiles.com/rdm8A4I2x9/TwoSolutions_rar
I don't know why a solution should also reference the ClassLibrary project or it can't modified when do <ReferenceProject> in FooProject. I got following error message when debug:
Do I need change something?
Currently there's no official solution for that.
So if anyone need what approach I collected and I modify some tags to prevent conflict PackageName with ProjectName, Here's final solution, Which original copied from https://github.com/dotnet/sdk/issues/1151#issuecomment-459275750
Many thanks to script author:
Here's enhancement version of it:
<PropertyGroup>
<ReplacePackageReferences Condition="'$(ReplacePackageReferences)' == ''">true</ReplacePackageReferences>
<ReplaceProjectReferences Condition="'$(ReplaceProjectReferences)' == ''">true</ReplaceProjectReferences>
</PropertyGroup>
<Choose>
<When Condition="'$(SolutionPath)' != '' AND '$(SolutionPath)' != '*undefined*' AND Exists('$(SolutionPath)')">
<PropertyGroup>
<SolutionFileContent>$([System.IO.File]::ReadAllText($(SolutionPath)))</SolutionFileContent>
<SmartSolutionDir>$([System.IO.Path]::GetDirectoryName( $(SolutionPath) ))</SmartSolutionDir>
<RegexPattern>(?<="[PackageName]", ")(.*)(?=", ")</RegexPattern>
<HasSolution>true</HasSolution>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<HasSolution>false</HasSolution>
</PropertyGroup>
</Otherwise>
</Choose>
<Choose>
<When Condition="$(ReplacePackageReferences) AND $(HasSolution)">
<ItemGroup>
<!-- Keep the identity of the packagereference -->
<SmartPackageReference Include="#(PackageReference)">
<InProject>false</InProject>
<PackageName>%(Identity)</PackageName>
<InSolution>$(SolutionFileContent.Contains('\%(Identity).csproj'))</InSolution>
</SmartPackageReference>
<!-- Filter them by mapping them to another itemGroup using the WithMetadataValue item function -->
<PackageInSolution Include="#(SmartPackageReference -> WithMetadataValue('InSolution', True) )">
<Pattern>$(RegexPattern.Replace('[PackageName]','%(PackageName)') )</Pattern>
<SmartPath>$([System.Text.RegularExpressions.Regex]::Match( '$(SolutionFileContent)', '%(Pattern)' ))</SmartPath>
<ProjName>'%(PackageName)'</ProjName>
</PackageInSolution>
<ProjectReference Include="#(PackageInSolution -> '$(SmartSolutionDir)\%(SmartPath)' )">
<Name>#(PackageInSolution -> %(ProjName))</Name>
</ProjectReference>
<!-- Remove the package references that are now referenced as projects -->
<PackageReference Remove="#(PackageInSolution -> '%(PackageName)' )" />
</ItemGroup>
</When>
<When Condition="$(ReplaceProjectReferences) AND '$(_RestoreSolutionFileUsed)' == ''">
<ItemGroup>
<!-- Keep the identity of the project reference (relative path), determine the project name and whether the project is contained in the current solution -->
<SmartProjectReference Include="#(ProjectReference)">
<OriginalIdentity>%(Identity)</OriginalIdentity>
<ProjectName>$([System.IO.Path]::GetFileNameWithoutExtension( $([System.IO.Path]::GetFullPath( '%(OriginalIdentity)' )) ))</ProjectName>
<InSolution>$(SolutionFileContent.Contains('\%(ProjectName).csproj'))</InSolution>
</SmartProjectReference>
<!-- Filter them by mapping them to another itemGroup using the WithMetadataValue item function -->
<ProjectNotInSolution Include="#(SmartProjectReference -> WithMetadataValue('InSolution', False) )">
</ProjectNotInSolution>
<!--Reference the latest version of the package (why not * ? > see https://github.com/NuGet/Home/issues/7328-->
<PackageReference Include="#(ProjectNotInSolution -> '%(ProjectName)' )" Version="*" />
<!-- Remove the project references that are now referenced as packages -->
<ProjectReference Remove="#(ProjectNotInSolution -> '%(OriginalIdentity)' )" />
</ItemGroup>
</When>
</Choose>
Note if you need to auto update nuget package then you must specify the package above the script provided above:
<ItemGroup>
<PackageReferen``ce Include="FooClassLibrary" Version="*"/>
</ItemGroup>
Feel free to modify or edit above script or edit the answer. If you found better answer please post it (Ex You create new extension for that or something).
I have an .NET Standard project where I implemented a module for an ASP.NET Core CMS framework. Currently, it uses the CMS framework libraries coming from NuGet packages. If I grab the source code of the CMS framework from GitHub and add my module to its solution and replace the package references to the actual project references it will work fine.
My goal is to make it work without updating the references in the csproj file so if the project is added to the full source code solution then use the project references, otherwise use the NuGet package references.
So let's say the .NET Standard project is called 'ModuleA'. It has a package reference to 'ModuleB':
<ItemGroup>
<PackageReference Include="ModuleB" Version="1.0.0" />
</ItemGroup>
When I want to use ModuleA in a solution where ModuleB is accessible then I use project reference to it:
<ItemGroup>
<ProjectReference Include="..\..\ModuleB\ModuleB.csproj" />
</ItemGroup>
I'd like to include both of them in the .csproj file somehow and make it to use the proper references on build (e.g. based on some conditions like project exists?).
If both are added to the csproj then the build will fail (e.g. 'Unable to find project ...ModuleB.csproj. Check that the project reference is valid and that project file exists.').
You could do that probably dynamically, but I think it's not really transparant how that would work.
I would recommend to add a configuration, e.g. in my example "Local-Debug" and use conditions in your csproj.
Example
Creating the configuration:
And in your csproj you could do this:
<ItemGroup>
<ProjectReference Condition="'$(Configuration)' == 'Local-Debug'" Include="otherProject.csproj" />
<PackageReference Condition="'$(Configuration)' != 'Local-Debug'" Include="otherProjectPackage" Version="2.4.1" />
</ItemGroup>
Your dependencies must be statically known and resolve-able at build-time. See #Julian's answer for a good config-driven build-time solution.
As a run-time solution: You can dynamically load your references at run-time. This way, you can search for the DLL you need in the working directory of your app and if you don't find it there, then download it (from Nuget or elsewhere), either as a binary that you can directly load, or as a source that you can build; and then load that library dynamically.
Here's how you can load an assembly dynamically (at run-time): https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.loadfrom?view=netframework-4.8
And this question: Loading library dynamically
Coding against a dynamically loaded assembly has its own quirks; you will need clear interface definitions for the referenced library, or else, you'll find yourself dealing with a lot of reflection and dynamics.
I'm trying to setup a library nuget package for .net core with the dotnet pack command, however, instead of just having a dll included in the nuget package, a content file from another references nuget is added (which makes the nuget file size 9.6MB instead of 59KB).
Is there a way to avoid getting files and content from other nuget packages in a nuget library project?
to reproduce:
Create a .net core library
Add Hl7.Fhir.Specification.STU3 nuget reference
run dotnet pack
The nuspec file in the newly created nuget package, will reveal that the specification.zip file is regarded as content that must be added.
I've tried testing with a custom nuspec file which is basicly a copy from the dotnet output, but without the content reference. The problem I see, is that the nuspec file contains a lot of references which must be maintained somehow.
Peter Wurzinger's suggestion worked for me. It's a shame he posted as a comment, rather than an answer, since he deserves the rep points. Anyway, this is my csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Hl7.Fhir.Specification.STU3" Version="0.96.0" ExcludeAssets="contentFiles" />
</ItemGroup>
</Project>
when I pack, the bin\Debug\test.1.0.0.nuspec file does not contain the specification.zip file elements that exists when I don't use ExcludeAssets.
I am able to read packages from NuGet.org but I am not able to read only certain packages from our private NuGet server - Klondike.
I tracked requests which VS2015 made to download package and query string which VS2015 sends to NuGet source is:
?$filter=IsAbsoluteLatestVersion&searchTerm='Package-ID'&targetFramework='net'&includePrerelease=true&$skip=0&$top=126
Problem is with parameter targetFramework. When VS2015 uses targetFramework='net' than it cannot read packages for framework net461, they are skipped.
When I executed request in Postman and set targetFramework='net461' then I am able to find package.
Also I noticed that VS2015 sporadically changing target framework from net to net461.
My question is: Do I need to configure my VS2015 or I have to change my NuGet package?
NuGet package is created form .NET Core 2.0 project and here is configuration:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<Company>Stackoverflow</Company>
<Authors>kat1330</Authors>
<Description>Package consists banch of functionalities.</Description>
<PackageTags>rules, rule engine</PackageTags>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<IncludeSource>True</IncludeSource>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\cert.snk</AssemblyOriginatorKeyFile>
<DelaySign>true</DelaySign>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<ApplicationIcon>favicon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
</Project>
UPDATE: Version of NuGet package manager is: 3.5.0.1484. It is latest what is offered on Visual Studio 2015 for me.
I am able to find packages form nuget.org and "certain packages" from private source. "Certain Packages" means some are visible and some not
Since you able to find packages form nuget.org and "certain packages" from private source ("Certain Packages" means some are visible and some not), so, the reason for the invisible package should be related to the package itself not about the nuget and private source.
According to the sample config for package, I noticed that the value of GeneratePackageOnBuild is set to False rather than True:
<PropertyGroup>
...
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
...
</PropertyGroup>
When the value is set to false, Visual Studio will not generate package. So, you should make sure if the package is generated. If it was generated, check if you can access it and download it.
Hope this helps.
I cannot get Microsoft.EntityFrameworkCore 2.0 to work with NETStandard.Library 2.0
Error CS0433 The type 'AttributeUsageAttribute' exists in both 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Contrived.Model.Schema D:\Contrived\Contrived\Framework\Contrived.Model.Schema\Attributes\EntityColumnAttribute.cs
My .csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="NETStandard.Library" Version="2.0.0" />
</ItemGroup>
</Project>
This also happens if i create a new solution and a netstandard 2.0 library then add entityframeworkcore 2.0
Error CS1703 Multiple assemblies with equivalent identity have been imported: 'D:\Users\maksymiuk_a.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Threading.Tasks.dll' and 'D:\Users\maksymiuk_a.nuget\packages\system.threading.tasks\4.3.0\ref\netstandard1.3\System.Threading.Tasks.dll'. Remove one of the duplicate references. ClassLibrary1 D:\Contrived\Contrived\ClassLibrary1\ClassLibrary1\CSC
Update: Visual Studio 2017 15.3 and the 2.0.0 SDK have been released. Use these versions to get rid of such conflicts.
This appears to be one of the build issues happening when using a mix of preview-tooling and "RTM" packages before all parts have been released.
To get the best support for 2.0.0 at the time of writing, do one of the following:
only use the same preview2 version of the nuget packages, the installed .NET Core SDK and the latest VS 2017 15.3 preview (15.3 Preview 7).
Use the latest VS 2017 15.3 Preview (Preview 7), install the 2.0.0 (not preview2) .NET Core Sdk from the CI build output at https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.0.0/dotnet-sdk-2.0.0-win-x64.exe (the same build output location is used by microsoft's 2.0.0 docker images)
The reason for this requirement is that the 2.0.0 SDK knows about these conflicts and trims the conflicting references (System.*.dll in this case) out of the projects.
This issue can still happen even with DOT NET Core 2+, and is caused when the packages you reference in your project depend on a different version of the same package, specifically same namespace.
There are 2.5 solutions that I know of:
1) If you control both packages, then update both to make sure they are using the same version of that dependency (or change the namespace of one of the versions of that dependency, like: Your.Thing.v3.Models)
2) If you can find one or both of those packages on an open source site like GitHub, you can download them and update them to use the same version of that dependency (or the namespace thing from option 1, above)
2.5) If you don't control or have access to the source of those packages, and I realize that this isn't really a solution... (hence the .5), then the last option is to stop using one of those packages.
If there's another way, I'd love to know about it.
Probably not the best idea out there, but try to remove the reference to System.Runtime manually by right-click on references and finding it there.
For me it worked to remove the reference to both assemblies and re-add them again.
Expand your project's References in the Solution Explorer --> Right click the faulty assembly -> Remove.
Then right click References -> Add Reference... -> check the boxes of the assemblies you just removed.
Then rebuild.
In my case I have added multiple reference in web.config file.
after removing one of them resolve the issue and working perfectly under local IIS server also