Je souhaite trouver Mes pages de rasoir de projet dans un autre assemblage. pour ce faire, j'écrire le code suivant:Localiser des pages de rasoir dans un autre assemblage
public void ConfigureServices(IServiceCollection services)
{
var adminAssembly = Assembly.Load(new AssemblyName("App"));
services.AddMvc().AddApplicationPart(adminAssembly).AddRazorOptions(options =>
{
var previous = options.CompilationCallback;
options.CompilationCallback = context =>
{
previous?.Invoke(context);
context.Compilation = context.Compilation.AddReferences(
MetadataReference.CreateFromFile(typeof(dodo).Assembly.Location));
};
});
services.Configure<RazorViewEngineOptions>(options =>
{
options.FileProviders.Add(new EmbeddedFileProvider(Assembly.Load("App")));
options.FileProviders.Add(new PhysicalFileProvider(@"C:\Users\soheil\Documents\Visual Studio 2017\Projects\WebApplication5\App"));
});
}
ma solution:
lors de l'exécution localhost:5000/SameTodo
Après erreur Get:
One or more compilation references are missing. Ensure that your project is referencing 'Microsoft.NET.Sdk.Web' and the 'PreserveCompilationContext' property is not set to false.
pile:
The type or namespace name 'SameTodoModel' could not be found (are you missing a using directive or an assembly reference?) + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } The type or namespace name 'SameTodoModel' could not be found (are you missing a using directive or an assembly reference?) + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; The type or namespace name 'SameTodoModel' could not be found (are you missing a using directive or an assembly reference?) + public SameTodoModel Model => ViewData.Model; The type or namespace name 'SameTodoModel' could not be found (are you missing a using directive or an assembly reference?) + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData;
et définir PreserveCompilationContext
à faux mais maintenant travaillé comment puis-je résoudre ce problème?
Je fais cela mais ne fonctionne pas. –
Pourriez-vous partager votre solution? Comme la publication sur Github? Vous manquez peut-être une directive 'using' avec l'espace de noms de la classe que vous utilisez sur cette vue rasoir? –