【问题标题】:Visual Studio / msbuild CopyToOutputDirectory - how does it work?Visual Studio / msbuild CopyToOutputDirectory - 它是如何工作的?
【发布时间】:2020-06-03 23:09:58
【问题描述】:

我正在使用 Visual Studio 社区:

Microsoft Visual Studio Community 2019
Version 16.4.5
VisualStudio.16.Release/16.4.5+29806.167
Microsoft .NET Framework
Version 4.8.03752

我有一个非常简单的 ASP.Net Core 网站/应用项目,目录结构如下:

website
 /bin
 /www
     /about
     /images

注意:webroot 目录不是 wwwroot,而只是 www

项目文件(.csproj)包含以下内容(将所有子目录/文件复制到输出目录):

   <ItemGroup>
      <Content Update="www\**\*">
         <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </Content> 
   </ItemGroup>

使用 Visual Studio(配置 = 调试)

   BUILD -> Rebuild Solution

结果:

/bin
    /Debug
          /netcoreapp3.0
                        /Properties
                        /runtimes

(缺少 /www 和所有子目录和文件!) - 为什么???

如果我在开发人员命令提示符下使用 msbuild.exe,将获得相同的结果;在配置方面没有区别(调试与发布)。

我假设 www 目录(和所有子目录)和文件将被复制到输出目录 - 但显然,这不会发生。我不明白为什么 CopyToOutputDirectory 被忽略了;我遗漏了一些东西,但搜索文档没有得到任何答案。

任何想法/建议将不胜感激。

提前致谢。

【问题讨论】:

    标签: visual-studio asp.net-core msbuild


    【解决方案1】:

    更新:

    只是在项目(.csproj)文件中更改了以下内容:

       <ItemGroup>
          <Content Update="www\**\*">
             <CopyToOutputDirectory>Always</CopyToOutputDirectory>
          </Content> 
       </ItemGroup>
    

    收件人:

       <ItemGroup>
          <None Update="www\**\*">
             <CopyToOutputDirectory>Always</CopyToOutputDirectory>
          </None> 
       </ItemGroup>
    

    使用 Visual Studio:BUILD -> 重建解决方案(成功)

    也尝试使用 msbuild.exe(成功)

    现在 www 目录和所有子目录/文件都出现在输出中——为什么?我怀疑是因为我没有使用默认的“wwwroot”作为内容目录,使用 不起作用,而 起作用;但这只是一种理论;我只知道它有效。

    还发现此 SO 链接对于描述 和 之间的差异很有用,对于那些好奇的人来说:

    What are the various "Build action" settings in Visual Studio project properties and what do they do?

    【讨论】:

      猜你喜欢
      • 2010-11-03
      • 1970-01-01
      • 1970-01-01
      • 2010-10-27
      • 2017-08-28
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多