MSBUILD 无法强制包目标的 PackageLocation

发布于 2024-11-28 07:03:30 字数 2045 浏览 0 评论 0原文

我正在尝试从 msbuild 为我的 Web 服务构建部署包,就像在 Visual Studio 中右键单击项目文件一样。

该包创建良好,并放置在项目文件源目录下的 /obj/Release/Packages 文件夹中。

您应该能够通过在项目文件内的 PropertyGroup 中设置 PackageLocation 属性来指定创建该包的位置。但是,这对我不起作用。它仍然将包放在源目录下的 /obj/Release/Packages 中。

以下是我的项目文件中的片段:

  <Import Project="$(SrcTreeRoot)\Build\TaskInit.Tasks" />
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
  <Import Project="$(SrcTreeRoot)\Build\TaskOverrides.Tasks" />
  <PropertyGroup>
    <Platform>Any Cpu</Platform>
    <Configuration>Dev</Configuration>
    <PackageLocation>$(PackageOutputDir)\MatrixOnCdsService\MatrixOnCdsService.zip</PackageLocation>
    <PackageAsSingleFile>True</PackageAsSingleFile>
    <EnablePackageProcessLoggingAndAssert>True</EnablePackageProcessLoggingAndAssert>
    <!--OutDir>$(PackageOutputDir)\MatrixOnCdsService\</OutDir-->
  </PropertyGroup>

我们还使用具有以下部分的 MasterBuild.proj:

    <PackageProject Include="..\Source\AnalysisSuite\MatrixOnCdsService\MatrixOnCdsService.csproj"/>

...

<Target Name="Package">
    <MSBuild Projects="@(PackageProject)" Targets="Package" Properties="Platform=$(Platform);
                                                                       Configuration=$(Configuration);
                                                                       DeployOnBuild=true;
                                                                       DeployTarget=Package;
                                                                       PackageLocation=$(PackageLocation);"/>
</Target>

TaskInit.tasks 是我们自己的自定义导入文件,其中包含 PackageOutputDir 属性,我们用它来告诉项目将其放在哪里包裹。

我的问题是,为什么即使在指定 PackageLocation 之后,包仍然放置在 /obj/Release/Packages 文件夹中?

I'm trying to build a deployment package for my web service from msbuild just like you can do in Visual Studio by right-clicking on the project file.

The package gets created fine and is put in the /obj/Release/Packages folder under my source directory for the project file.

You should be able to specify where that package is created by setting the PackageLocation property in a PropertyGroup inside the project file. However, that is not working for me. It still puts the package in /obj/Release/Packages under the source directory.

Here is the snippet from my project file:

  <Import Project="$(SrcTreeRoot)\Build\TaskInit.Tasks" />
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
  <Import Project="$(SrcTreeRoot)\Build\TaskOverrides.Tasks" />
  <PropertyGroup>
    <Platform>Any Cpu</Platform>
    <Configuration>Dev</Configuration>
    <PackageLocation>$(PackageOutputDir)\MatrixOnCdsService\MatrixOnCdsService.zip</PackageLocation>
    <PackageAsSingleFile>True</PackageAsSingleFile>
    <EnablePackageProcessLoggingAndAssert>True</EnablePackageProcessLoggingAndAssert>
    <!--OutDir>$(PackageOutputDir)\MatrixOnCdsService\</OutDir-->
  </PropertyGroup>

We are also using a MasterBuild.proj that has the following sections:

    <PackageProject Include="..\Source\AnalysisSuite\MatrixOnCdsService\MatrixOnCdsService.csproj"/>

...

<Target Name="Package">
    <MSBuild Projects="@(PackageProject)" Targets="Package" Properties="Platform=$(Platform);
                                                                       Configuration=$(Configuration);
                                                                       DeployOnBuild=true;
                                                                       DeployTarget=Package;
                                                                       PackageLocation=$(PackageLocation);"/>
</Target>

TaskInit.tasks is our own custom import file that contains the PackageOutputDir property that we use to tell the project where to put the package.

My question is why is the package still being placed in the /obj/Release/Packages folder even after specifying the PackageLocation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

相对绾红妆 2024-12-05 07:03:30

将您拥有的属性组粘贴到目标中:

<Target Name="SetValues">
  <PropertyGroup>
    <Platform>Any Cpu</Platform>
    <Configuration>Dev</Configuration>
    <PackageLocation>$(PackageOutputDir)\MatrixOnCdsService\MatrixOnCdsService.zip</PackageLocation>
    <PackageAsSingleFile>True</PackageAsSingleFile>
    <EnablePackageProcessLoggingAndAssert>True</EnablePackageProcessLoggingAndAssert>
    <!--OutDir>$(PackageOutputDir)\MatrixOnCdsService\</OutDir-->
  </PropertyGroup>
</Target>

然后将其添加为您的包目标的 DependsOnTarget,我认为您将传递您的值。

例如

Stick the property group you have in a target:

<Target Name="SetValues">
  <PropertyGroup>
    <Platform>Any Cpu</Platform>
    <Configuration>Dev</Configuration>
    <PackageLocation>$(PackageOutputDir)\MatrixOnCdsService\MatrixOnCdsService.zip</PackageLocation>
    <PackageAsSingleFile>True</PackageAsSingleFile>
    <EnablePackageProcessLoggingAndAssert>True</EnablePackageProcessLoggingAndAssert>
    <!--OutDir>$(PackageOutputDir)\MatrixOnCdsService\</OutDir-->
  </PropertyGroup>
</Target>

then add this as a DependsOnTarget for your Package Target and i think you will have your values passed.

e.g. <Target Name="Package" DependsOnTargets="SetValues">

逐鹿 2024-12-05 07:03:30

您可以在 MasterBuild.proj 中执行以下操作。

  <Target Name="Package">
    <ConvertToAbsolutePath Paths="$(PackageOutputDir)">
      <Output TaskParameter="AbsolutePaths" PropertyName="Source_Dir_Abs"/>
    </ConvertToAbsolutePath>
   <MSBuild Projects="@(PackageProject)" Targets="Package"
      properties="Platform=$(Platform);
      Configuration=$(Configuration);
      DeployOnBuild=false;
      DeployTarget=Package;
      PackageLocation=$(Source_Dir_Abs)\$(PackageProjectName).zip;
      PackageAsSingleFile=true;
      ExcludeFilesFromDeployment=Web.config;
      _PackageTempDir=$(PackageOutputDir)\temp;">
  </MSBuild>
  </Target>

在调用 msbuild 的地方,您需要添加一个将在 $(PackageProjectName) 中使用的属性,方法如下:

msbuild.exe /property:PackageProjectName=$project

You could do the following in your MasterBuild.proj.

  <Target Name="Package">
    <ConvertToAbsolutePath Paths="$(PackageOutputDir)">
      <Output TaskParameter="AbsolutePaths" PropertyName="Source_Dir_Abs"/>
    </ConvertToAbsolutePath>
   <MSBuild Projects="@(PackageProject)" Targets="Package"
      properties="Platform=$(Platform);
      Configuration=$(Configuration);
      DeployOnBuild=false;
      DeployTarget=Package;
      PackageLocation=$(Source_Dir_Abs)\$(PackageProjectName).zip;
      PackageAsSingleFile=true;
      ExcludeFilesFromDeployment=Web.config;
      _PackageTempDir=$(PackageOutputDir)\temp;">
  </MSBuild>
  </Target>

Where you are calling msbuild you will need to add a property that will be used in $(PackageProjectName) by doing the following:

msbuild.exe /property:PackageProjectName=$project

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文