You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何设置ASP.NET MVC项目中引用Web项目的输出子目录?

解决方案

你可以通过修改项目引用的配置,传递额外的MSBuild属性来指定被引用Web项目的输出目录,具体操作如下:

  • 在ASP.NET MVC项目的.csproj文件中,找到对应的ProjectReference节点,添加<AdditionalProperties>配置项,将被引用项目的发布输出路径指定为wwwroot下的目标子目录(示例中为wwwroot/client):
<ItemGroup>
  <ProjectReference Include="..\callcenter.client\callcenter.client.esproj">
    <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
    <AdditionalProperties>WebPublishDir=$(PublishDir)wwwroot\client</AdditionalProperties>
  </ProjectReference>
</ItemGroup>

补充说明

  • $(PublishDir)是MSBuild内置变量,指向当前项目的发布输出根目录(即你提到的bin文件夹)。
  • WebPublishDir属性会传递给被引用的esproj项目,覆盖其默认发布输出路径,将产物直接输出到主项目发布目录下的指定子目录中。
  • 如果需要本地调试时也生效,可以同时添加OutDir属性调整本地构建的输出路径:
<AdditionalProperties>WebPublishDir=$(PublishDir)wwwroot\client;OutDir=$(MSBuildProjectDirectory)\bin\wwwroot\client</AdditionalProperties>

内容的提问来源于stack exchange,提问作者Mohamed RT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 01:37:09