I am building a website using asp.net core mvc, and for the login i added dependency for enc.dll file, which just encrypt/decrypt user information. I made a Seeder class with en
UPDATE
This issue was fixed in 2.0.3, for apply need to update VS(or manualy dotnet SDK and Runtime) and project packages via nuget(in particular Microsoft.AspNetCore.All to 2.0.3)
It's known issue of .Net Core 2.0 https://github.com/dotnet/core-setup/issues/2981
Razor view precompilation can not resolve lib path
Here workaround to get this work:
add this (it's fixing release publish error)
using Microsoft.AspNetCore.Mvc;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyModel;
using Microsoft.Extensions.DependencyModel.Resolution;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace somenamespace
{
public class MvcConfiguration : IDesignTimeMvcBuilderConfiguration
{
private class DirectReferenceAssemblyResolver : ICompilationAssemblyResolver
{
public bool TryResolveAssemblyPaths(CompilationLibrary library, List assemblies)
{
if (!string.Equals(library.Type, "reference", StringComparison.OrdinalIgnoreCase))
{
return false;
}
var paths = new List();
foreach (var assembly in library.Assemblies)
{
var path = Path.Combine(ApplicationEnvironment.ApplicationBasePath, assembly);
if (!File.Exists(path))
{
return false;
}
paths.Add(path);
}
assemblies.AddRange(paths);
return true;
}
}
public void ConfigureMvc(IMvcBuilder builder)
{
// .NET Core SDK v1 does not pick up reference assemblies so
// they have to be added for Razor manually. Resolved for
// SDK v2 by https://github.com/dotnet/sdk/pull/876 OR SO WE THOUGHT
/*builder.AddRazorOptions(razor =>
{
razor.AdditionalCompilationReferences.Add(
MetadataReference.CreateFromFile(
typeof(PdfHttpHandler).Assembly.Location));
});*/
// .NET Core SDK v2 does not resolve reference assemblies' paths
// at all, so we have to hack around with reflection
typeof(CompilationLibrary)
.GetTypeInfo()
.GetDeclaredField("k__BackingField")
.SetValue(null, new CompositeCompilationAssemblyResolver(new ICompilationAssemblyResolver[]
{
new DirectReferenceAssemblyResolver(),
new AppBaseCompilationAssemblyResolver(),
new ReferenceAssemblyPathResolver(),
new PackageCompilationAssemblyResolver(),
}));
}
}
}
and this (it's fixing compilation errors)
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.PortableExecutable;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.DependencyModel;
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
namespace somenamespace
{
public class ReferencesMetadataReferenceFeatureProvider : IApplicationFeatureProvider
{
public void PopulateFeature(IEnumerable parts, MetadataReferenceFeature feature)
{
var libraryPaths = new HashSet(StringComparer.OrdinalIgnoreCase);
foreach (var assemblyPart in parts.OfType())
{
var dependencyContext = DependencyContext.Load(assemblyPart.Assembly);
if (dependencyContext != null)
{
foreach (var library in dependencyContext.CompileLibraries)
{
if (string.Equals("reference", library.Type, StringComparison.OrdinalIgnoreCase))
{
foreach (var libraryAssembly in library.Assemblies)
{
libraryPaths.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, libraryAssembly));
}
}
else
{
foreach (var path in library.ResolveReferencePaths())
{
libraryPaths.Add(path);
}
}
}
}
else
{
libraryPaths.Add(assemblyPart.Assembly.Location);
}
}
foreach (var path in libraryPaths)
{
feature.MetadataReferences.Add(CreateMetadataReference(path));
}
}
private static MetadataReference CreateMetadataReference(string path)
{
using (var stream = File.OpenRead(path))
{
var moduleMetadata = ModuleMetadata.CreateFromStream(stream, PEStreamOptions.PrefetchMetadata);
var assemblyMetadata = AssemblyMetadata.Create(moduleMetadata);
return assemblyMetadata.GetReference(filePath: path);
}
}
}
}
also change addMVC to this
//workaround https://github.com/dotnet/core-setup/issues/2981 will be fixed in 2.0.1
services.AddMvc().ConfigureApplicationPartManager(manager =>
{
var oldMetadataReferenceFeatureProvider = manager.FeatureProviders.First(f => f is MetadataReferenceFeatureProvider);
manager.FeatureProviders.Remove(oldMetadataReferenceFeatureProvider);
manager.FeatureProviders.Add(new ReferencesMetadataReferenceFeatureProvider());
});
and you will able to use dll in your view
also you have second way is disable razor precompilation here example Deleting PrecompiledViews.dll from ASP.Net Core 2 API