Публикация приложения ASP.NET Core 2.1 с использованием веб-развертывания, не включая все представления и папки приложений. - PullRequest
0 голосов
/ 05 февраля 2019

Я пытаюсь развернуть свое приложение .net core 2.1 на сервере IIS с помощью webdeploy, но после публикации приложения в каталоге публикации нет папок и файлов, в том числе и из-за пределов wwwroot, и в папке View я вижу только 2 Viewстраница и эти представления поступают из другой библиотеки, отличной от основного проекта, но не создается сгенерированное представление, принадлежащее основному проекту.

Program.cs

public static void Main(string[] args)
{
   CreateWebHostBuilder(args).UseDefaultServiceProvider(options =>
    options.ValidateScopes = false).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
       .UseStartup<Startup>();

Части файла Startup.cs

// For those 2 Views that are coming from another assembly (this 2 views are present in the Views folder of publish directory)
var myAssembly = typeof(Component).Assembly; 

services.AddMvc()
    .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
    .AddApplicationPart(myAssembly); 

    services.Configure<RazorViewEngineOptions>(options =>
    {
         options.FileProviders.Add(new EmbeddedFileProvider(myAssembly, "MyNS")); 
    });
    //For serving static files from folder call Contents, outside of wwwroot
    app.UseStaticFiles();
    app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider(
           Path.Combine(_env.ContentRootPath, "Contents")),
        RequestPath = "/Contents"
    });

.csproj

<Project Sdk="Microsoft.NET.Sdk.Web"> 
<PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <UserSecretsId>........</UserSecretsId>
  </PropertyGroup>

  <ItemGroup> 
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Tools" Version="1.1.0-preview4-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0-preview3-35497" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0-preview3-35497">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0-preview3-35497" />
    <PackageReference Include="morelinq" Version="3.0.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Proj.Business\Proj.Business.csproj" />
    <ProjectReference Include="..\Proj.Common\Proj.Common.csproj" />
    <ProjectReference Include="..\Proj.Data\Proj.Data.csproj" />
    <ProjectReference Include="..\MyNS\MyNS.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Contents\" CopyToPublishDirectory="PreserveNewest" />
    <Folder Include="PrivateContents\" CopyToPublishDirectory="PreserveNewest" />
  </ItemGroup>  
</Project>

Я получаю тот же результат, когда публикую приложение в службе приложений Azure. Что не так с моим приложением?Есть ли что-то еще, чтобы следовать развернуть приложение asp.net core 2.1?пожалуйста, помогите.

1 Ответ

0 голосов
/ 06 февраля 2019

Просто изменить

<Folder Include="Contents\" CopyToPublishDirectory="PreserveNewest" />
<Folder Include="PrivateContents\" CopyToPublishDirectory="PreserveNewest" />

На

<Content Include="Contents\**\*" CopyToPublishDirectory="PreserveNewest" />
<Content Include="PrivateContents\**\*" CopyToPublishDirectory="PreserveNewest" />
...