简体   繁体   English

MsBuild Target不起作用

[英]MsBuild Target doesn't work

I want to change .csproj file to execute my target after I make publish on server from Visual Studio 2017. 从Visual Studio 2017在服务器上发布后,我想更改.csproj文件以执行我的目标。

<PropertyGroup>
    <PostBuildEvent>copy $(ProjectDir)\lib\Oracle.ManagedDataAccess.dll $(ProjectDir)\bin</PostBuildEvent>
  </PropertyGroup>
  <PropertyGroup>
    <PreBuildEvent>copy $(ProjectDir)\lib\Oracle.ManagedDataAccess.dll $(ProjectDir)\bin</PreBuildEvent>
  </PropertyGroup>  

  <ItemGroup>
    <OracleSourceFile Include="$(ProjectDir)\lib\Oracle.ManagedDataAccess.dll"/>
    <OracleDestinationFolder Include="$(ProjectDir)\bin"/>
  </ItemGroup>

  <Target Name="OracleTarget" AfterTargets="MSDeployPublish" >        
   <Copy
        SourceFiles="@(OracleSourceFile)"
        DestinationFolder="@(OracleDestinationFolder)">        
    </Copy>
  </Target>

But this doesn't work. 但这是行不通的。 I don't see in publish output that my target was executed. 我在发布输出中看不到目标已执行。 What I do wrong? 我做错了什么?

After reading the Microsoft best practices about deploying web application , specially at this page (which talks about Deploying Extra Files), I finally modified my .pubxml like below: 在阅读了有关部署Web应用程序Microsoft最佳实践之后,特别是在此页面上该页面讨论了部署额外的文件),我终于修改了.pubxml,如下所示:

<Target Name="OracleCollectFiles">
    <ItemGroup>
      <OracleSourceFile Include="lib\**\*" />     
      <FilesForPackagingFromProject Include="%(OracleSourceFile.Identity)">
        <DestinationRelativePath>bin\%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>

<PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      OracleCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>

    <CopyAllFilesToSingleFolderForMsdeployDependsOn>
      OracleCollectFiles;
      $(CopyAllFilesToSingleFolderForMsdeployDependsOn);
    </CopyAllFilesToSingleFolderForMsdeployDependsOn>
  </PropertyGroup>

</Project>

MsBuild Target doesn't work MsBuild Target不起作用

You may publish your project from File System . 您可以从File System发布项目。 The target "MSDeployPublish" is not supported by the File System . File System不支持目标“ MSDeployPublish”。

"We currently do not support executing custom targets after publish from VS for the file system protocol. If you publish from the command line the target will be executed however." “从VS发布文件系统协议后,我们当前不支持执行自定义目标。但是,如果从命令行发布,则将执行目标。”

So, we could use MSBuild command line to execute this custom target by specify the target, /t:OracleTarget : 因此,我们可以使用MSBuild命令行通过指定目标/t:OracleTarget来执行此自定义目标:

msbuild "YourSolutionFile" /t:Build,OracleTarget /p:DeployOnBuild=true /p:PublishProfile=YourPublishFile.pubxml

Besides , another solution for this issue, you can use target CopyAllFilesToSingleFolderForPackage instead of MSDeployPublish : 此外 ,针对此问题的另一种解决方案 ,您可以使用目标CopyAllFilesToSingleFolderForPackage而不是MSDeployPublish

  <Target Name="OracleTarget" AfterTargets="CopyAllFilesToSingleFolderForPackage" >        
   <Copy
        SourceFiles="@(OracleSourceFile)"
        DestinationFolder="@(OracleDestinationFolder)">        
    </Copy>
  </Target>

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM