dll.refresh 使用 devenv 与 msbuild(网站项目,而非应用程序)

dll.refresh with devenv vs msbuild (Website Project, not application)

我正在为我们的应用程序创建一个 CI 服务器,并且 运行 遇到了我们网站项目的 msbuild 问题。它构建了一个解决方案,但没有 proj 文件(因为它不是网站应用程序,也不可能是)。 MSBuild 不会将 dll.refresh 文件拉入 bin 文件夹。 (不特定于 CI 问题,但这是目标)如果我 运行 它反对 devenv.com (CLI 尝试)构建然后它确实拉入 dll.refresh 并出现工作得很好。

根据我在 MsBuild 日志中找到的内容,似乎复制任务(这只是 msbuild 本身的默认规则)在查找 DLL 文件时不以 /bin 文件夹为目标,而是以根目录为目标解决方案(在本例中为 /www)。

只是在寻找更多信息,因为此时所有其他研究点似乎都 运行 枯燥。 (它必须是 Msbuild 吗?不,但我想使 CI 配置非常简单,以便其他人重新生成和自定义构建 script/batch 文件和 VS 安装在 CI 服务器会使它变得更加复杂)。

谢谢。

我无法使用 VS2013/MSBuild 12.0.31101.0 重现您描述的行为。

转载:

  1. 在 VS 中创建新网站
  2. 在磁盘上添加对程序集的引用
  3. 清除 bin 目录中除 *.refresh
  4. 之外的所有文件
  5. 全部保存
  6. 运行 msbuild WebsiteSolution.sln

结果:*.refresh 中引用的 DLL 被重新创建。

通读生成的 MSBuild 文件表明 *.refresh 文件中的路径是相对于网站的基本目录解析的。我会注意到这只发生在 Build 目标上,所以我不知道你说 "the Copy task [...] is the default rule" 是什么意思。也许您正在使用一些需要包含默认目标的自定义 MSBuild 目标?

生成的MSBuild(用MSBuildEmitSolution=1生成)的相关部分:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
  <PropertyGroup>
    <!-- Edit: Snipped -->
    <!-- The website location is stored relative to the .sln -->
    <!-- (which is the same as the location of the temporary msbuild file) -->
    <Project_[...]_AspNetPhysicalPath>..\..\WebSites\WebSite1\</Project_[...]_AspNetPhysicalPath>
    <!-- Edit: Snipped -->
  </PropertyGroup>
  <ItemDefinitionGroup />
  <!-- Edit: Snipped -->
  <Target Name="Build" Condition=" ('$(CurrentSolutionConfigurationContents)' != '') and (false or ( ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') ) or ( ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') )) " DependsOnTargets="GetFrameworkPathAndRedistList">
    <!-- Edit: Snipped -->
    <!-- *.refresh items are discovered and saved in [...]_References_RefreshFile -->
    <CreateItem Include="$(Project_[...]_AspNetPhysicalPath)\Bin\*.refresh">
      <Output TaskParameter="Include" ItemName="Project_[...]_References_RefreshFile" />
    </CreateItem>
    <!-- The contents of the *.refresh are read to [...]_References_ReferenceRelPath -->
    <ReadLinesFromFile Condition=" '%(Project_[...]_References_RefreshFile.Identity)' != '' " File="%(Project_[...]_References_RefreshFile.Identity)">
      <Output TaskParameter="Lines" ItemName="Project_[...]_References_ReferenceRelPath" />
    </ReadLinesFromFile>
    <!-- Those contents are relative to [...]_AspNetPhysicalPath -->
    <CombinePath BasePath="$(Project_[...]_AspNetPhysicalPath)" Paths="@(Project_[...]_References_ReferenceRelPath)">
      <Output TaskParameter="CombinedPaths" ItemName="Project_[...]_References" />
    </CombinePath>
    <!-- This seems to be a no-op, since you cannot copy if it doesn't exist -->
    <Copy Condition="!Exists('%(Project_[...]_References.Identity)')" ContinueOnError="true" SourceFiles="@(Project_[...]_References->'%(FullPath)')" DestinationFolder="$(Project_[...]_AspNetPhysicalPath)\Bin\" />
    <!-- Edit: Snipped -->
    <!-- This will copy [...]_References to [...]_References_CopyLocalFiles and add references -->
    <ResolveAssemblyReference Condition="Exists('%(Project_[...]_References.Identity)')" Assemblies="@(Project_[...]_References->'%(FullPath)')" TargetFrameworkDirectories="$(Project_[...]__TargetFrameworkDirectories)" FullFrameworkFolders="$(Project_[...]__FullFrameworkReferenceAssemblyPaths)" SearchPaths="{RawFileName};{TargetFrameworkDirectory};{GAC}" FindDependencies="true" FindSatellites="true" FindSerializationAssemblies="true" FindRelatedFiles="true" TargetFrameworkMoniker=".NETFramework,Version=v4.5">
      <Output TaskParameter="CopyLocalFiles" ItemName="Project_[...]_References_CopyLocalFiles" />
    </ResolveAssemblyReference>
    <!-- [...]_References_CopyLocalFiles is copied to the bin directory -->
    <Copy Condition="(false) or ('$(AspNetConfiguration)' == 'Debug') or ('$(AspNetConfiguration)' == 'Release')" SourceFiles="@(Project_[...]_References_CopyLocalFiles)" DestinationFiles="@(Project_[...]_References_CopyLocalFiles->'$(Project_[...]_AspNetPhysicalPath)\Bin\%(DestinationSubDirectory)%(Filename)%(Extension)')" />
    <!-- Edit: Snipped -->
  </Target>
  <!-- Edit: Snipped -->
</Project>

我没有在没有安装 VS 的机器上尝试过,所以它可能不能直接应用,但是你绝对可以使用生成的 metaproj 文件构建,即使没有 Visual Studio 已安装。

我也遇到了这个问题;问题实际上是我们的构建配置既不是 Debug 也不是 Release,所以 msbuild 实际上跳过了编译(因此使用 *.refresh 进行了恢复):

Skipping because the "Dev" configuration is not supported for this web project. You can use the AspNetConfiguration property to override the configuration used for building web projects, by adding /p:AspNetConfiguration= to the command line. Currently web projects only support Debug and Release configurations.