別のアセンブリでマイプロジェクトカミソリページを探したい。 これを行うために、私は次のコード書き込み:他のアセンブリでカミソリページを見つける
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"));
});
}
私の解決策:
後のエラーを取得localhost:5000/SameTodo
を実行している:
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.
スタック:
を10The 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;
とはfalseにPreserveCompilationContext
を設定したが、今、私はこの問題を解決することができますどのように働いていましたか?
私はこれを行うが、動作しません。 –
何とかあなたのソリューションを共有できますか?それをGithubに公開するのと同じですか?あなたは、おそらくあなたがその剃刀のビューで使用しているクラスの名前空間を持つ 'using'ディレクティブを見逃していますか? –