我在VS 2012中有一个Web应用程序项目,当我使用Web发布工具时,它成功地构建了,但没有将任何文件复制到发布目标(在这种情况下是文件系统)。

如果我看构建输出,我可以看到一切都被复制到obj\Release\Package\PackageTmp\正确,但然后我在构建输出中看到的是这样的:

4>完成建设项目“{project}.csproj”。 4>删除现有文件… 4>发布文件夹/… 4 > ========== 构建:3成功了,0失败,1最新的,0跳过 ========== ========== 发布:1成功,失败,0跳过 ==========

即使它说发布成功,但目标目录中没有用于发布的文件。

我在多个项目中看到过这种情况,有时似乎是解决方案/平台配置导致了这个问题,但我还不能确定造成这个问题的确切原因。

有人见过这种情况吗?或者有人知道如何让它正确工作吗?

更新:

我可能找到了一个变通办法。这又发生了,我把发布设置弄乱了。一旦我改变了设置选项卡上选择的配置到另一个配置,然后回到我想要使用的所有文件再次开始发布。希望这在未来的其他项目中也适用。

更新2:

我在Microsoft Connect上发布了一个bug,并从VS Web developer团队的开发人员那里得到了回复。他说他们已经在内部版本中修复了这个问题,并将很快发布发布工具的更新来修复这个问题。

更新3:

最近Visual Studio 2012 Update 2修复了这个问题


当前回答

最简单的是,

   1. select the file(s) that are not being copied,
   2. Press <F4> to get the properties window
   3. Make the "Build Action" property "compile" or "content" depending on what it is.
   4. Now this particular file will be included!

其他回答

我尝试了所有这些解决方案,但这是一个有效的每一次。

我们只需将“Publish method:”从“File System”更改为“Web Deploy”,然后立即将其更改为“File System”。

这可能是由vs2012的RC创建的解决方案/项目造成的。这在几个月前发生在我身上,通过确保我的解决方案构建配置与我的项目配置匹配来解决这个问题……

我最近在使用VS2012 Express for Web打开vs2012RC中最初创建的相同解决方案时遇到了同样的问题。我完全按照最初海报上的建议做了,它解决了我的问题。

下面是我找到答案的线索:

connect.microsoft.com/VisualStudio/feedback/details/746321/publish-web-application-fails

上述对话中对我有帮助的中肯回答是:

Posted by Microsoft on 6/13/2012 at 12:00 PM Hi Andrew, This was a bug in how we handle the solution configuration vs. the project configuration. We incorrectly assumed that they would be the same (e.g. Solution's Release|x86 would have each project set to Release|x86 as well), which caused us to use the wrong build properties for publishing files. The workaround is to make the solution configuration and build configuration match. This issue will be fixed in the next release of Visual Studio 2012. Thanks, - Jimmy Lewis SDET, Visual Web Developer team

不管怎样,我最终放弃了与Web Deploy的斗争,让它做我想做的事情(复制可部署的文件,不做其他任何事情),所以我在PowerShell中编写了脚本,对结果非常满意。它比我通过MSBuild/Web Publish尝试的任何方法都快得多,大概是因为这些方法仍然在做我不需要的事情。

以下是要点(字面意思):

function copy-deployable-web-files($proj_path, $deploy_dir) {
  # copy files where Build Action = "Content" 
  $proj_dir = split-path -parent $proj_path
  [xml]$xml = get-content $proj_path
  $xml.Project.ItemGroup | % { $_.Content } | % { $_.Include } | ? { $_ } | % {
    $from = "$proj_dir\$_"
    $to = split-path -parent "$deploy_dir\$_"
    if (!(test-path $to)) { md $to }
    cp $from $to
  }

  # copy everything in bin
  cp "$proj_dir\bin" $deploy_dir -recurse
}

在我的例子中,我在CI环境(TeamCity)中调用它,但它也可以很容易地连接到构建后事件中。

尝试退出Visual Studio,删除相关的pubxml。在你的PublishProfiles目录下,重新启动VS并发布。参与VS 2019的工作。

这是因为.pubxml. xml。User包含发布所需的信息,该文件没有(也不应该)包含在源代码控制中。要修复这个VS错误,请从.pubxml. xml文件中复制信息。用户文件到.pubxml文件。相关属性为:

<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>

把它们放到.pubxml中,就可以开始了。