I got a couple of projects made with asp.net core that I wanted to export to NuGet. Everything was fine with the first version (0.9.0). But when I updated a package to 0.9.1, I started having version issues, cause the app started looking for all dependencies with version 0.9.1 (even though only one was updated and the others remained at 0.9.0)
Could anyone check my config and see where am I making my mistake?
Thanks!
These are the errors I got:
FileLoadException: Could not load file or assembly 'Framework.Web, Version=0.9.1.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
FileLoadException: Could not load file or assembly 'Framework.Web, Version=0.9.1.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
This is my nuspec file:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<!-- Required elements-->
<id>Framework.Web.Mvc</id>
<version>0.9.1</version>
<description>Framework web MVC library</description>
<authors>Lucas Leite</authors>
<!-- Optional elements -->
<dependencies>
<dependency id="Framework.Web" version="0.9.0" />
<dependency id="Framework.Model" version="0.9.0" />
<dependency id="Microsoft.AspNetCore.Localization.Routing" version="1.1.2" />
<dependency id="Microsoft.AspNetCore.Mvc" version="1.1.3" />
</dependencies>
<!-- ... -->
</metadata>
<!-- Optional 'files' node -->
<files>
<file src="bin\Release\netcoreapp1.1\Framework.Web.Mvc.dll" target="lib\netcoreapp1.1" />
<file src="bin\Release\netcoreapp1.1\Framework.Web.Mvc.xml" target="lib\netcoreapp1.1" />
<file src="bin\Release\netcoreapp1.1\pt-BR\Framework.Web.Mvc.resources.dll" target="lib\netcoreapp1.1\pt-BR" />
</files>
</package>
Try to change dependency version to (,0.9.0]:
<dependency id="Framework.Web" version="(,0.9.0]" />
Accordingly to Nuget dependency versioning,
<!-- Accepts any version 0.9.0 and above -->
<dependency id="Framework.Web" version="0.9.0" />
and
<!-- Accepts any version up below or include 0.9.0-->
<dependency id="ExamplePackage" version="(,0.9.0]" />
Related
I have a C# library, let say "Utilities" that uses Log4net as dependency, I am using .net framwork 4.6.1, I finished developeing this library and do a nuget pack Utilities.projcs and then push this package.
While I'm try to use this Utilities in another project that which is an asp.net core "2.1" project, I got this exception
**Method not found: 'log4net.ILog log4net.LogManager.GetLogger(System.String)'.**
System.MissingMethodException
HResult=0x80131513
Message=Method not found: 'log4net.ILog log4net.LogManager.GetLogger(System.String)'.
Source=Utilities
StackTrace:
at Utilities.Logging.MyLogManager.GetLogger(String loggerKey)
My Utilities nuget spec file
<?xml version="1.0"?>
<package >
<metadata>
<id>Utilities</id>
<version>1.2.0</version>
<title>Internal Utilities</title>
<authors>My Team</authors>
<owners>My Team</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This dll contains parsers,loggers and other functionalities that is commonly used.</description>
<releaseNotes>Rlease notes</releaseNotes>
<copyright>Copyright 2020</copyright>
<tags>Utilities</tags>
<dependencies>
<dependency id="log4net" version="2.0.8" include="all"/>
</dependencies>
</metadata>
<files>
<file src="bin\Debug\log4net.dll" target="" />
<file src="bin\Debug\log4net.xml" target="" />
<file src="bin\Debug\Utilities.dll" target="" />
</files>
</package>
Any ideas to solve this, I spent the last couple of days to solve it but no luck
NOTE: When I add Reference manually by location in my pc (My library + Log4net) it works fine!!
Create class library in .net standard.
For more info about .net standard visit https://learn.microsoft.com/en-us/dotnet/standard/net-standard
How to create .net standard class library -> https://learn.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio?tabs=csharp
How to create .net standard Nuget -> https://learn.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio?tabs=netcore-cli
this image will help you understand the concept behind shared libraries.
After upgrading Newtonsoft.Json to version 9.0.0 and ReactJS.Net packages to 2.5.0, the TransformBabel.proj stopped working:
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="TransformBabel">
<!-- ReactJS.NET - Transpile JavaScript via Babel -->
<UsingTask AssemblyFile="$(OutputPath)\React.MSBuild.dll" TaskName="TransformBabel" />
<Target Name="TransformBabel">
<TransformBabel SourceDir="$(MSBuildProjectDirectory)" />
</Target>
</Project>
Returning the following:
TransformBabel.proj(6, 3): error MSB4018: The "TransformBabel" task failed unexpectedly.
[Exec] TransformBabel.proj(6, 3): error MSB4018: React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.IReactSiteConfiguration ---> System.TypeInitializationException: The type initializer for 'React.ReactSiteConfiguration' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
It seems that it cannot load the Newtonsoft 6.0.0.0 version. The web.config has an assembly redirection:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
But I am not sure that, as it is starting a new msbuild process, if it is being ignored. I would like to hint msbuild the location of the assembly, but no success until now.
A bit late to the party here, but hopefully my experience will help to anyone else having the same problem.
I have recently experienced the same issue with React.MSBuild 3.1.0. It seems that it has hardcoded a specific version as I have updated my Newtonsoft.Json to the latest (10.0.3) using NuGet and set redirection correctly, but the build kept failing on the same error as you have mentioned.
What I did is simply uninstall all the React packages (MSBuild and Core) and also Newtonsoft.Json (using -force as there were other dependencies) and then let NuGet install the React.MSBuild again. It has installed it with all dependencies what resulted in obtaining Newtonsoft.Json 9.0.1.
Not sure why do they restrict Newtonsoft.Json library to a specific version, but it is more a question to React developers. Unless you need a latest (or other specific version of it), this should fix the problem.
I know this is an old post...but here is my workaround:
I put Newtonsoft.Json.dll v6.0.0.0 into Tools directory relative to the project directory and let msbuild copy it to $(OutputPath) to satisfy TransformBabel task condition.
My TransformBabel.proj looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="TransformBabel">
<!-- ReactJS.NET - Transpile JavaScript via Babel -->
<UsingTask AssemblyFile="$(OutputPath)\React.MSBuild.dll" TaskName="TransformBabel" />
<Target Name="TransformBabel">
<Copy SourceFiles="$(MSBuildProjectDirectory)\Tools\Newtonsoft.Json.dll" DestinationFolder="$(OutputPath)" />
<TransformBabel SourceDir="$(MSBuildProjectDirectory)" />
</Target>
</Project>
After this TransformBabel task is finished, then let msbuild overwrite Newtonsoft.Json.dll v6.0.0.0 in $(OutputPath) with whatever Newtonsoft.Json.dll version my project is actually using, ex: v8.0.3.
So, in the main project .csproj, I have something like this:
<ItemGroup>
...
<Reference Include="React.MSBuild, Version=2.3.0.0, Culture=neutral, PublicKeyToken=9aed67b161f7db78, processorArchitecture=MSIL">
<HintPath>Tools\React.MSBuild.dll</HintPath>
<Private>True</Private>
</Reference>
...
</ItemGroup>
...
<ItemGroup>
...
<Content Include="Tools\Newtonsoft.Json.dll" />
<Content Include="Tools\React.MSBuild.dll" />
...
</ItemGroup>
...
<Target Name="TransformBabel" AfterTargets="Build">
<Exec Command=""$(msbuildtoolspath)\msbuild.exe" $(ProjectDirectory)TransformBabel.proj /p:OutputPath=$(OutputPath) /nr:false" />
</Target>
<Target Name="AfterTransformBabel" AfterTargets="TransformBabel">
<Copy SourceFiles="..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll" DestinationFolder="$(OutputPath)" />
</Target>
Replace the path Newtonsoft.Json.8.0.3 inside AfterTransformBabel task to your need.
I'm trying to integrate Nutch 2.3 in order to push data to the latest Elasticsearch 2.1.1.
I started updating versions and dependencies in the following files:
indexer-elastic/plugin.xml
<plugin id="indexer-elastic" name="ElasticIndexWriter" version="1.0.0"
provider-name="nutch.apache.org">
<runtime>
<library name="indexer-elastic.jar">
<export name="*" />
</library>
<library name="elasticsearch-2.1.1.jar"/>
<library name="hppc-0.7.1.jar"/>
<library name="jackson-core-2.6.2.jar"/>
<library name="jackson-dataformat-cbor-2.6.2.jar"/>
<library name="jackson-dataformat-smile-2.6.2.jar"/>
<library name="jackson-dataformat-yaml-2.6.2.jar"/>
<library name="guava-18.0.jar"/>
<library name="compress-lzf-1.0.2.jar"/>
<library name="t-digest-3.0.jar"/>
<library name="jsr166e-1.1.0.jar"/>
<library name="commons-cli-1.3.1.jar"/>
<library name="netty-3.10.5.Final.jar"/>
<library name="joda-time-2.8.2.jar"/>
<library name="lucene-analyzers-common-5.3.1.jar"/>
<library name="lucene-backward-codecs-5.3.1.jar"/>
<library name="lucene-core-5.3.1.jar"/>
<library name="lucene-highlighter-5.3.1.jar"/>
<library name="lucene-join-5.3.1.jar"/>
<library name="lucene-memory-5.3.1.jar"/>
<library name="lucene-queries-5.3.1.jar"/>
<library name="lucene-queryparser-5.3.1.jar"/>
<library name="lucene-spatial-5.3.1.jar"/>
<library name="lucene-suggest-5.3.1.jar"/>
<library name="HdrHistogram-2.1.6.jar"/>
<library name="joda-convert-1.2.jar"/>
</runtime>
<requires>
<import plugin="nutch-extensionpoints" />
</requires>
<extension id="org.apache.nutch.indexer.elastic"
name="Elasticsearch Index Writer"
point="org.apache.nutch.indexer.IndexWriter">
<implementation id="ElasticIndexWriter"
class="org.apache.nutch.indexwriter.elastic.ElasticIndexWriter" />
</extension>
</plugin>
indexer-elastic/ivy.xml
<ivy-module version="1.0">
<info organisation="org.apache.nutch" module="${ant.project.name}">
<license name="Apache 2.0" />
<ivyauthor name="Apache Nutch Team" url="http://nutch.apache.org" />
<description>Apache Nutch</description>
</info>
<configurations>
<include file="../../..//ivy/ivy-configurations.xml" />
</configurations>
<publications>
<!--get the artifact from our module name -->
<artifact conf="master" />
</publications>
<dependencies>
<dependency org="org.elasticsearch" name="elasticsearch"
rev="2.1.1" conf="*->default" />
<dependency org="com.google.guava" name="guava" rev="18.0" />
</dependencies>
</ivy-module>
I also reworked org.apache.nutch.indexwriter.elastic.ElasticIndexWriter to work against the new interface of the elasticsearch 2.1.1 client.
So what is the problem?
It seems that the dependencies listed in indexer-elastic/plugin.xml are not loaded automatically at runtime. Therefore elasticsearch client cannot benefit from them and throws exceptions..
So i tried a different approach adding the dependencies one by one according to the exception it gives me in $NUTCH_ROOT/ivy/ivy.xml where the main dependencies of Apache Nutch are listed. That's not the right approach but it's kind of working.
How to deal with plugin dependencies?
What is the strategy for using newer version of a library in the plugin. For example Nutch uses Guava v11.0.2 but Elasticsearch 2.1.1 requires Guava v18.0. Although i'm specifying it explicitly in indexer-elastic/ivy.xml it seems to load the old version at runtime.
Plugin dependencies should be declared both in the plugin's ivy.xml and in the plugin.xml files. I haven't tested the files you included but cannot see anything immediately wrong with them. As you pointed out, declaring the deps in the main ivy file is not great.
See this note on how to upgrade the Tika plugin, the same logic applies to all the plugins.
As for resolving conflicts between the main dependencies and the ones from the plugins, unfortunately you'll have to deal with it yourself e.g. force the version you need in the main ivy.xml as Nutch does not handle the plugins as dependencies (in the Maven sense) of the main code.
NuGet obtains packages from our own gallery server. A script then creates a CMAKE script with global variables for each package location. I want to add package specific variables like BOOST_INCLUDEDIR or BOOST_LIBRARYPATH with package relative pathes into the .nuspec file of the package. However, all variables shall be usable in CMAKE later.
The .nuspec xsd schema does not allow additional properties. Is there another solution ?
Here is an example of what I need:
<?xml version="1.0"?>
<package>
<metadata>
<id>boost_x86_src</id>
<version>1.55.0</version>
<authors>Fabian Stern</authors>
<owners>Fabian Stern</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Test Package</description>
<dependencies />
<frameworkAssemblies />
<references>
<reference file="signature.sig" />
</references>
<properties>
<add key="BOOST_INCLUDEDIR" value="include/win32" />
<add key="BOOST_LIBRARYPATH" value="libs/win32" />
</properties>
</metadata>
</package>
I want to publish the dependencies of a module seperately from the jar artifact of the module.
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
<info organisation="com.mycompany" module="platform" />
<configurations defaultconfmapping="release->*;compile->*" defaultconf="release">
<conf name="release" />
<conf name="compile" extends="release" />
</configurations>
<publications>
<artifact name="platform-api" type="jar" ext="jar" />
</publications>
<dependencies>
<dependency org="com.google.inject" name="guice" rev="3.0" />
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.6" />
<dependency org="com.google.guava" name="guava" rev="13.0-rc1" conf="compile" />
<dependency org="log4j" name="log4j" rev="1.2.17" conf="compile" />
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.6.6" conf="compile" />
</dependencies>
</ivy-module>
For the configuration above, I want an artifact that includes guice & slf4j-api jars only, without the platform-api.jar. My current solution is to define two dependencies in the dependent module, one transitive and other not:
<dependency org="com.mycompany" name="platform" rev="1.0-SNAPSHOT" conf="myconf->release">
<exclude org="com.mycompany" />
</dependency>
<dependency org="com.mycompany" name="platform" rev="1.0-SNAPSHOT" transitive="false" conf="myotherconf->release" />
But this solution causes problems when the third module is dependent on both of these modules, and it is just ugly.
Try this instead:
<ivy-module version="2.0">
<info organisation="com.mycompany" module="platform" />
<configurations>
<conf name="default" description="runtime dependencies and master artifact can be used with this conf" extends="runtime,master"/>
<conf name="master" description="contains only the artifact published by this module itself, with no transitive dependencies"/>
<conf name="compile" description="Compile dependencies"/>
<conf name="runtime" description="Runtime dependencies, includes compile dependencies" extends="compile"/>
</configurations>
<publications>
<artifact name="platform-api" type="jar" ext="jar" conf="master"/>
</publications>
<dependencies>
<!-- Compile dependencies -->
<dependency org="com.google.inject" name="guice" rev="3.0" conf="compile->default"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.6" conf="compile->default"/>
<dependency org="com.google.guava" name="guava" rev="13.0-rc1" conf="compile->default" />
<!-- Runtime dependencies -->
<dependency org="log4j" name="log4j" rev="1.2.17" conf="runtime->default" />
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.6.6" conf="runtime->default" />
</dependencies>
</ivy-module>
Notes:
Note the "extends" attribute on the configurations, used to create larger sets of jars.
I recommend remove the default configuration mapping and explicitly set a conf mapping on each depedency. Simpler and ultimately easier to understand in my opinion (less magic)
Now that your module has separate configurations for the published artifacts and it's runtime dependencies a single dependency declaration can be used as follows to map these to separate local configurations:
<dependency org="com.mycompany" name="platform" rev="1.0-SNAPSHOT" conf="myconf->runtime;myotherconf->master" />
I think, what you are looking for is actually two projects sharing the same dependencies. (and by coincidence one of them is using the other as well).
Did you consider using extends http://ant.apache.org/ivy/history/latest-milestone/ivyfile/extends.html with:
extendType="dependencies".
Then you would have your platform extending the the parent-ivy.xml with the dependencies. And your Other project extending the same parent-ivy.xml file for the same dependencies.
I'm not sure if this is enough. Since the configurations will play role here. But maybe it's a start.