Error Could not load file or assembly 'Nlog, version=4.0.0.0, culture=neutral, publickeytoken=5120e14c030593c' - sharepoint-2013

I have a 2 Sharepoint projects Sharepoint-Svr-App & Sharepoint-svr-Job in one solution and both projects have the NLog reference. Publishing those two projects generates the corresponding *.wsp files without any issue. When I deploy the solution, Sharepoint-svr-App gets deployed without any issue but Sharepoint-Svr-Job failes with Error:
Could not load file or assembly 'Nlog, version=4.0.0.0, culture=neutral, publickeytoken=5120e14c030593c'
Please find the attached screenshot here
Entries inside Sharepoint-Srv-App.csproj are given below:
<ItemGroup>
<Reference Include="NLog">
<HintPath>packages\NLog.4.4.5\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="NLog.Web">
<HintPath>packages\NLog.Web.4.4.0\lib\net35\NLog.Web.dll</HintPath>
</Reference>
<ItemGroup>
and Sharepoint-Srv-Job.csproj looks like
<ItemGroup>
<Reference Include="NLog">
<HintPath>..\Sharepoint-Svr-App\packages\NLog.4.4.5\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="NLog.Web">
<HintPath>..\Sharepoint-Svr-App\packages\NLog.Web.4.4.0\lib\net35\NLog.Web.dll</HintPath>
</Reference>
<ItemGroup>
packages.config file in both projects is same like below:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="4.4.5" targetFramework="net45" />
<package id="NLog.Config" version="4.4.5" targetFramework="net45" />
<package id="NLog.Schema" version="4.4.5" targetFramework="net45" />
<package id="NLog.Web" version="4.4.0" targetFramework="net45" />
</packages>

Issue got resolved
Try to add your external dlls into your solution and check.
Go to your Package.package->Advanced.
Here is one thread for your reference.
https://social.technet.microsoft.com/Forums/office/en-US/7642b88a-4046-4429-a9d2-e2088c86f3fd/deploying-custom-dlls-in-sharepoint-2013?forum=sharepointadmin

Related

Specify architecture and Debug/Release modes in *nuspec file to publish a DLL C++ project

I have a Visual Studio C++ project that creates a DLL for both x86 and x64 architectures in Debug and Release modes. I should publish this package as a nuget package with regards to these specifications. So I should have 4 DLLs in my package. My question is how to specify x86, x64 in my nuspec file. I was thinking whether it should be specified in the target field of each file but I can't find any documentation on how to exactly specify these specifications.
My nuspec file looks like the following:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<!-- Required elements-->
<id>counterpartylookup</id>
<version>0.0.0</version>
<description>counterpartylookup/v140/win32/x86/x64</description>
<authors>***</authors>
<!-- Optional elements -->
<!-- ... -->
<owners>...</owners>
<licenseUrl>***</licenseUrl>
<projectUrl>***</projectUrl>
<dependencies>
***
</dependencies>
<tags> {vc140, win32, x64, x86, dynamic, C++, native}</tags>
</metadata>
<files>
<file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="lib" />
<file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target="lib" />
<file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target="lib" />
<file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target="lib" />
</files>
<!-- Optional 'files' node -->
</package>
My question is how to specify x86, x64 in my nuspec file.
You need to place the dlls in a folder named runtimes within sub-folders named {platform}-{architecture}\lib{framework} or {platform}-{architecture}\native.
The folder structure:
\runtimes
\x86
\Debug
\Release
\x64
\Debug
\Release
The nuspec file is like:
<files>
<file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="runtimes\ x64\Release " />
<file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target=" runtimes\ x64\Debug " />
<file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target=" runtimes\ x86\Release " />
<file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target=" runtimes\ x86\Debug " />
</files>
The related documents: Architecture-specific folders and Adding the native implementation libraries.
Or you could try another:
1) create a file called <package_id>.targets file in your project folder. In your side, you should name it as counterpartylookup.targets:
write these under it:
<Project>
<ItemGroup Condition="'$(Platform)'=='x64' and '$(Cofiguration)'=='Debug'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x64\Debug\CounterPartyLookup.dll"></Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)'=='x86' and '$(Cofiguration)'=='Debug'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x86\Debug\CounterPartyLookup.dll"></Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)'=='x64' and '$(Cofiguration)'=='Release'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x64\Release\CounterPartyLookup.dll"></Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)'=='x86' and '$(Cofiguration)'=='Release'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x86\Release\CounterPartyLookup.dll"></Reference>
</ItemGroup>
</Project>
2) modify your nuspec file:
<files>
<file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="Reference\x64\Release" />
<file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target="Reference\x64\Debug" />
<file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target="Reference\x86\Release" />
<file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target="Reference\x86\Debug" />
<file src="counterpartylookup.targets" target="build"/>
</files>
3) repack your c++ project and then before you install the new one, you should delete all nuget caches under C:\Users\xxx(current user)\.nuget\packages

Force project references to be included in netstandard nuget package

I have a netstandard project which includes two project references. Visual studio 2017 is being used to build the nukpg. When the project is built the produced nupkg only contains the assembly produced by that project and lists the two project references as nuget dependencies. Is there a way to force the packaging to include those assemblies as lib files?
csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<RootNamespace>Verifier.Observations.DevOps.Health</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<VersionPrefix>1.0.1</VersionPrefix>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Verifier.Observations.Aspects\Verifier.Observations.Aspects.csproj" />
<ProjectReference Include="..\Verifier.Observations\Verifier.Observations.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.ComponentModel.Composition"/>
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
Update
Based upon feedback from #alexgiondea-msft the package is now created as desired using the following
csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>1.0.1</VersionPrefix>
<TargetFramework>net462</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NuspecFile>Verifier.Observations.DevOps.Health.Nuspec</NuspecFile>
<NuspecProperties>version=$(VersionPrefix);id=$(MSBuildProjectName);author=$(Authors);copy=$(Copyright);iconUrl=$(PackageIconUrl)</NuspecProperties>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Verifier.Observations.Aspects\Verifier.Observations.Aspects.csproj" />
<ProjectReference Include="..\Verifier.Observations\Verifier.Observations.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
nuspec
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<iconUrl>$iconUrl$</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Inspect automation service to ensure it is up and operational</description>
<releaseNotes></releaseNotes>
<copyright>$copy$</copyright>
<tags>verifier-observation-plugin automation</tags>
<dependencies>
<group targetFramework="net462" />
</dependencies>
<references>
<group targetFramework="net462">
<reference file="Verifier.Observations.DevOps.Automation.dll" />
</group>
</references>
</metadata>
<files>
<file src="bin\*\net462\*.dll" target="lib\net462" />
<file src="bin\*\net462\*.pdb" target="lib\net462" />
</files>
</package>
You can control where assemblies are deployed in the nuget package using an item in an itemgroup, similar to this:
<ItemGroup>
<None Include="!!path_to_assembly!!">
<PackagePath>lib\net462</PackagePath>
<Pack>true</Pack>
<Visible>false</Visible>
</None>
</ItemGroup>
That should include the specified assembly in the package.
You can add the following target to your .csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net47</TargetFrameworks>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ClassLibrary2\ClassLibrary2.csproj" PrivateAssets="all" />
<ProjectReference Include="..\ClassLibrary3\ClassLibrary3.csproj" Condition="'$(TargetFramework)' == 'net47'" PrivateAssets="all" />
</ItemGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
<ItemGroup>
<BuildOutputInPackage Include="#(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
</ItemGroup>
</Target>
</Project>
Source 1
Source 2
Reference: Advanced extension points to create customized package

Unable to Build/Run Multiple Frameworks Using VS 2017's Csproj

I'm using the JavaScript Services Angular infrastructure to build an Angular project that utilizes Entity Framework. I was able to produce a similar project in the past by modifying the project.json file but project settings are now set in the csproj file in VS2017. Below is my code based on Microsoft's recommendations for adapting project.json files to csproj:
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework> <-- Tried with and without ths line -->
<TargetFrameworks>netcoreapp1.1;net452</TargetFrameworks>
<RuntimeIdentifiers>win7-x64</RuntimeIdentifiers>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="Microsoft.CSharp" Version="1.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
...
On Build I get the following error referencing several files in my project:
Error CS0012 The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
With the <TargetFramework> tag removed, no netcoreapp1.1 references were found.

MSBuildWorkspace.Create() throws exception

I have Visual Studio 2013. I also have installed MSBuild Tools 2013. The following code gives me exception
var workspace=MSBuildWorkspace.Create();
Here is the exception
Could not load file or assembly 'Microsoft.Build, Version=14.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The system cannot find the file specified.
What am I doing wrong ?
You need to install the BuildTools for Visual Studio 2015.
You could compile Roslyn against an older version of MSBuild to avoid this problem. I've done this with VS 2012:
Src/Workspaces/Core/Workspaces.csproj
- <Reference Include="Microsoft.Build, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
- <Reference Include="Microsoft.Build.Framework, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <Reference Include="Microsoft.Build" />
+ <Reference Include="Microsoft.Build.Framework" />
Src/Workspaces/CSharp/CSharpWorkspace.csproj
- <Reference Include="Microsoft.Build, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
- <Reference Include="Microsoft.Build.Framework, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
- <Reference Include="Microsoft.Build.Tasks.$(MSBuildAssemblyNameFragment), Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <Reference Include="Microsoft.Build" />
+ <Reference Include="Microsoft.Build.Framework" />
+ <Reference Include="Microsoft.Build.Tasks.v4.0" />
Basically I strip the strong name (note that the name of the Tasks assembly is different though) so it picks up the MSBuild from the GAC which comes with the .NET Framework, which for me is the version VS 2012 used.

Sharp architecture 2.0 unit testing

I am just trying to test some validation which involves the database. The setup of my test code looks something like this:
[TestFixture]
public class UserValidatorTester : RepositoryTestsBase
{
[SetUp]
public void Setup()
{
ServiceLocatorInitializer.Init();
base.SetUp();
}
...
The ServiceLocatorInitializer looks like this:
public class ServiceLocatorInitializer
{
public static void Init()
{
IWindsorContainer container = new WindsorContainer();
container.Register(
Component
.For(typeof(IEntityDuplicateChecker))
.ImplementedBy(typeof(EntityDuplicateChecker))
.Named("entityDuplicateChecker"));
container.Register(Component.For(typeof(ISessionFactoryKeyProvider)).ImplementedBy(typeof(DefaultSessionFactoryKeyProvider)).Named("sessionFactoryKeyProvider"));
ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));
}
}
I am getting:
at SharpArch.Domain.SafeServiceLocator`1.GetService()
at SharpArch.NHibernate.SessionFactoryKeyHelper.GetKeyFrom(Object anObject)
at SharpArch.NHibernate.NHibernateRepositoryWithTypedId2.get_Session()
at EID2.Tasks.Repositories.UserRepository.SaveOrUpdate(User entity) in C:\Users\csetzkorn\Documents\Visual Studio 2010\Projects\EID2\Solutions\EID2.Tasks\Repositories\UserRepository.cs:line 17
at EID2.Tasks.UserTasks.CreateUser(CreateUserViewModel CreateUserViewModel) in C:\Users\csetzkorn\Documents\Visual Studio 2010\Projects\EID2\Solutions\EID2.Tasks\UserTasks.cs:line 33
at EID2.Tests.Validation.UserValidatorTester.LoadTestData() in C:\Users\csetzkorn\Documents\Visual Studio 2010\Projects\EID2\Solutions\EID2.Tests\Validation\UserValidatorTester.cs:line 39
at SharpArch.Testing.NUnit.NHibernate.RepositoryTestsBase.SetUp()
--NullReferenceException
at Microsoft.Practices.ServiceLocation.ServiceLocator.get_Current()
at SharpArch.Domain.SafeServiceLocator1.GetService()
Christian
PS:
Included dlls:
<ItemGroup>
<Reference Include="Castle.Core">
<HintPath>..\..\Packages\Castle.Core.2.5.2\lib\SL4\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Castle.Windsor">
<HintPath>..\..\Packages\Castle.Windsor.2.5.3\lib\NET40\Castle.Windsor.dll</HintPath>
</Reference>
<Reference Include="CommonServiceLocator.WindsorAdapter">
<HintPath>..\..\Packages\CommonServiceLocator.WindsorAdapter.1.0\lib\NET35\CommonServiceLocator.WindsorAdapter.dll</HintPath>
</Reference>
<Reference Include="EID2.Tasks">
<HintPath>..\xxx.Tasks\bin\Debug\xxx.Tasks.dll</HintPath>
</Reference>
<Reference Include="FluentValidation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a82054b837897c66, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Packages\FluentValidation\FluentValidation.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.ServiceLocation">
<HintPath>..\..\Packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
<Reference Include="MvcContrib.TestHelper">
<HintPath>..\..\Packages\MvcContrib.Mvc3-ci.3.0.68.0\lib\MvcContrib.TestHelper.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\ReferencedAssemblies\NHibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="NHibernate.ByteCode.Castle">
<HintPath>..\..\ReferencedAssemblies\NHibernate\NHibernate.ByteCode.Castle.dll</HintPath>
</Reference>
<Reference Include="NHibernate.Validator">
<HintPath>..\..\ReferencedAssemblies\NHibernate\NHibernate.Validator.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\..\Packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Rhino.Mocks">
<HintPath>..\..\ReferencedAssemblies\RhinoMocks\Rhino.Mocks.dll</HintPath>
</Reference>
<Reference Include="SharpArch.Domain">
<HintPath>..\..\ReferencedAssemblies\SharpArchitecture\SharpArch.Domain.dll</HintPath>
</Reference>
<Reference Include="SharpArch.NHibernate">
<HintPath>..\..\ReferencedAssemblies\SharpArchitecture\SharpArch.NHibernate.dll</HintPath>
</Reference>
<Reference Include="SharpArch.Testing">
<HintPath>..\..\ReferencedAssemblies\SharpArchitecture\SharpArch.Testing.dll</HintPath>
</Reference>
<Reference Include="SharpArch.Testing.NUnit">
<HintPath>..\..\ReferencedAssemblies\SharpArchitecture\SharpArch.Testing.NUnit.dll</HintPath>
</Reference>
<Reference Include="SharpArch.Tests">
<HintPath>..\..\ReferencedAssemblies\SharpArchitecture\SharpArch.Tests.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite">
<HintPath>..\..\Packages\System.Data.SQLite.1.0.66.0\lib\System.Data.SQLite.DLL</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\ReferencedAssemblies\ASP.NET MVC\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
PPS:
sql lite config
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
<property name="connection.connection_string">Data Source=:memory:;Version=3;New=True;</property>
<property name="connection.release_mode">on_close</property>
<property name="show_sql">true</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
</session-factory>
</hibernate-configuration>
There is a couple of the things that could go wrong with sqlite and there are different solutions for different problems, I think the problem you having is because sqlite.dll was built against .net System.Data while what you have is .net 4 System.Data, try adding:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
to the configuration element in the test app.config.
Also, if you are on x64 machine, and are referencing the x86 sqlite, then you need to change the target framework for your test assembly to x86 (right click project, select properties, build tab, and select x86 for the target framework)
The issue is that the NHibernate Session factory cannot be created. Read the error message:
System.ArgumentException : Unable to find the requested .Net Framework Data Provider. It may not be installed.
Do you have the SQLLite dll included in your project?
System.Data.SQLite.dll