使用BeforePublish Target帮助newby [英] Help a newby with BeforePublish Target

查看:100
本文介绍了使用BeforePublish Target帮助newby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为发布例程的一部分,我想完成许多任务,而不必独立于VS(2013)运行脚本.因此,我试图通过调整文件来学习如何使用MSBuild.到目前为止,这是我失败了.

There are a number of tasks I would like to accomplish as part of the publishing routine without having to run scripts independently of VS(2013). So I am trying to learn how to use MSBuild by adjusting files. Here's what I've failed at so far.

-目标(目前为1)是在源位置备份现有的应用程序文件夹

- Objective (1, for now) is to backup the existing application folder at the source

-我已将属性< publishBackup>添加到publish.xml文件中,指定了备份位置

- I've added a property,<publishBackup>, to the publish.xml file, specifying where to backup

-然后将其添加到.csproj文件

- Then added this to the .csproj file

  <目标名称="BeforePublish">
    <消息文本=发布之前" />
    <复制条件=``'$(配置)| $(平台)'=='LSATest | AnyCPU''' 
SourceFiles =''$(publishUrl)'\ ** \ *.*'" 
DestinationFolder ='''''$(publishBackup)''''' 
SkipUnchangedFiles ="true">
< Output TaskParameter =" CopiedFiles" ItemName =成功复制文件"/>
    </Copy>
    <消息文本=发布前". />
  </Target>

  <Target Name="BeforePublish">
    <Message Text="Before Publish START" />
    <Copy Condition="'$(Configuration)|$(Platform)' == 'LSATest|AnyCPU'" 
SourceFiles="'$(publishUrl)'\**\*.*" 
DestinationFolder="'$(publishBackup)'" 
SkipUnchangedFiles="true">
<Output TaskParameter="CopiedFiles" ItemName="SuccessfullyCopiedFiles"/>
    </Copy>
    <Message Text="Before Publish END" />
  </Target>

-我希望至少会收到一条消息.发布成功,但不会发生复制.我是完全不吃午餐了吗,是在添加这样的任务是傻瓜的事,还是有一个简单的解决方案?谢谢大家.

- I would have expected to get a message at least. The publish succeeds, but the copy doesn't happen. Am I totally out-to-lunch, is adding tasks like this a fool's errand, or is there a simple solution to this? Thanks all.

推荐答案


您好ARM15,


Hello ARM15,

由于您没有任何消息,因此我们应该调查您的MSBuild任务的详细信息.

Since you do not have any message, we should look into details of your MSBuild tasks.

1.您的MSBuild命令是什么?

1. What's your MSBuild command?

2. publish.xml的用途是什么?我知道您提到了< publishBackup>标签.在publish.xml中,但在MSBuild中,属性位于项目文件的PropertyGroup中.尽管您可能会看到:可以在整个项目中引用属性 使用语法

2. What is the use of publish.xml? I know you mentioned the tag <publishBackup> in publish.xml, but in MSBuild property are located in PropertyGroup of a project file. Although you may see this:" Properties can be referenced throughout the project file by using the syntax


(PropertyName). "例如,它仍然意味着项目文件xxxx.csproj.为什么不将您的财产放到PropertyGroup中?
(PropertyName). " It still means the project file xxxx.csproj for example. Why not put your property in the PropertyGroup?

这是MSBuild属性参考页:

Here is the MSBuild property reference page:

https://msdn.microsoft.com/en-us/library/dd393574.aspx

3.您的复制任务似乎没有问题.但是由于我无法测试,您应该自己检查一下.

3. Your copy task seems do not have problem. But as I cannot test, you should check it yourself.

总的来说,我认为您最好从一个简单的示例开始,然后向其中添加一些内容,以完成您的工作.

In general, I think you'd better start with a simple sample and add things to it in order to finish your job.

这是我的环境中的一个简单示例:

Here is a simple sample in my environment:

//Add the following the your csproj 
<ItemGroup>
        <MySourceFiles Include="Form1.cs"/>
</ItemGroup>
//Add the following the your csproj, it is the target, 
//I haven't add condition here
<Target Name="BeforePublish" >
    <Message Text="Before Publish START" />
    <Copy
            SourceFiles="@(MySourceFiles)"
            DestinationFolder="D:\Destination"
        />
    <Message Text="Before Publish END"/>
  </Target>

我的msbuild命令:

My msbuild command:

D:\ WinFormCases \ SimpleMSbuild \ SimpleMSbuild> msbuild.exe SimpleMSbuild.csproj/t:BeforePublish

D:\WinFormCases\SimpleMSbuild\SimpleMSbuild>msbuild.exe SimpleMSbuild.csproj /t:BeforePublish

您可以看到结果:

最诚挚的问候,


这篇关于使用BeforePublish Target帮助newby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆