我有三个 ASP.NET Core 7 项目:
Common
:图书馆项目。其他项目依赖于它。Web
:剃刀页面项目。取决于Common
。Migrator
:控制台项目。取决于数据库上下文等的 Common
和 Web
(通过 ProjectReference
)。它仅在内部使用,用于迁移和其他任务。dotnet publish Migrator.csproj
产生:
Pages/ <-----
Foo/
Page1.cshtml
Page2.cshtml
Bar/
Page1.cshtml
etc...
appsettings.json
Migrator
Web <-----
Web.runtimeconfig.json <-----
Web
项目的资产包含在Migrator
项目的已发布输出中。请注意,这不适用于 Common
项目的资产(包含在 Migrator
可执行文件中)。
我试图排除
Migrator.csproj
中的那些额外资产,但没有成功:
<ItemGroup>
<Content Update="Web*.*" CopyToPublishDirectory="Never" />
<Content Update="wwwroot/**" CopyToPublishDirectory="Never" />
</ItemGroup>
我也尝试过:
<ItemGroup>
<Content Remove="Web*.*" />
<Content Remove="Pages/**" />
</ItemGroup>
我也尝试过:
<ItemGroup>
<ProjectReference Include="../Common/Common.csproj" />
<ProjectReference Include="../Web/Web.csproj" ><IncludeAssets>none</IncludeAssets></ProjectReference>
</ItemGroup>
如何排除那些不必要的资产?
下面是排除 appsettings.json 的示例,您可以修改网页代码:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Content Remove="appsettings.json" />
</ItemGroup>
<ItemGroup>
<None Include="appsettings.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" />
</ItemGroup>
</Project>
或:
1.在“解决方案资源管理器”窗口中,右键单击该文件,然后单击“属性”。
2.在“属性”窗口中的“构建操作”行中,选择“无”
您可以阅读排除特定文件和文件夹了解更多信息。