3

I have an asp.net MVC project and front-end which build via npm command.

and provide app folder after the build. enter image description here

This folder does not include to my csproj file.

When i deploy from teamcity, im use 2 steps.

  1. publish application
  2. FTP deployment for /app folder (each file separately)

But ftp deployment very very slow. How can I deploy this folder as 'package'?

Perhaps I can dynamically include it to csproj file, or something else?

Artem Polishchuk
  • 505
  • 5
  • 17

1 Answers1

3

But ftp deployment very very slow. How can I deploy this folder as 'package' ?

Indeed, FTP deploy a folder with many files will be slower. Because it only open a single thread, and only uploads a single file at a time. You can consider zip that folder by a MSBuild target:

  <ItemGroup>
    <Content Include="app\**\*.*" />
  </ItemGroup>

  <Import Project="..\.build\MSBuild.Community.Tasks.Targets" />

  <Target Name="AfterBuild">
    <PropertyGroup>
      <ZipPackagePath>bin</ZipPackagePath>
    </PropertyGroup>
    <Zip Files="@(Link)" WorkingDirectory="$(ZipPackagePath)" ZipFileName="output\ZipName.zip" ZipLevel="9" />
  </Target>

Note: You need add the nuget package "MSBuildTasks" and you can change the ReleasePath to other folder.

But you still need to unzip that zip file after FTP deploy.

Perhaps I can dynamically include it to csproj file, or something else?

Alternatively, you can dynamically include it to your project file and it is what we recommendation.

To accomplish this, unload your project. Then at the very end of the project, just before the end-tag, place below scripts:

  <Target Name="AddAppFiles" AfterTargets="Build">
    <ItemGroup>
      <Content Include="app\**\*.*" />
    </ItemGroup>
  </Target>

After publishing, the app folder is included in the target location:

enter image description here

Note:

  1. With this target, the folder app does not appear in the Solution Explorer(dynamically include).

  2. If the app folder is generated after building complete, you can change the AfterTargets="Build" to BeforeTargets="_CheckForInvalidConfigurationAndPlatform", like:

<Target Name="AddAppFiles" BeforeTargets="_CheckForInvalidConfigurationAndPlatform">

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • i added target ` ` but this doesn't work – Artem Polishchuk Nov 23 '17 at 12:33
  • @ArtemPolischuk, That because you are using asp.net MVC project, whcih does not include the target `Publish`. So if you using `BeforeTargets="Publish"` MSBuild could not call this target(Only clickonce publish have publish target, WPF, Windows Form etc.). You can change it to `AfterTargets="Build"` or `BeforeTargets="_CheckForInvalidConfigurationAndPlatform"`. – Leo Liu Nov 23 '17 at 12:53
  • This work, when i trying deploy from visual studio. But, when i deploying from teamcity, that doesn't work. my TC settings: Targets: Rebuild `/p:Platform="Any CPU" /p:DeployOnBuild=True /p:Configuration=WebClient.Release /p:PublishProfile="web" /p:ProfileTransformWebConfigEnabled=True /p:_DestinationType=AzureWebSite /p:MSDeployPublishMethod=WMSVC /p:username=zz /p:Password=zz /p:SkipExtraFilesOnServer=True` – Artem Polishchuk Nov 23 '17 at 13:49
  • @ArtemPolischuk, You should check the build log to find the reason why the target not executed. At this moment, I have no TC environment to test your settings. If you still not make this work on TC, you can share your TC configuration and build log, I will try to find some useful info. – Leo Liu Nov 24 '17 at 04:36
  • i've added target "Rebuild' to csproj and all work correctly – Artem Polishchuk Nov 24 '17 at 19:49
  • @LeoLiu-MSFT Ithas been some time but can you tell me where did you put those nodes ? .csproj or some other file? – Genato Nov 09 '18 at 14:10
  • 1
    @Genato, Yes, the project file, `.csproj`. – Leo Liu Nov 09 '18 at 14:38
  • @LeoLiu-MSFT Ok, just to be clear this question is about Visual Studio FTP Publish? If yes, I'am trying to publish Web Forms via FTP Publish. I added MSBuildTasks via Nuget and added exact node as you `...... ` but at the begining of Publish .zip file is created in folder "output\ZipName.zip" as stated in "ZipFileName" property and Publish continue normally. (Files are sent normal not zipped). – Genato Nov 09 '18 at 14:47
  • 1
    @Genato, Since I do not have enough info about you, I suggest that you can post a new thread with detailed info about your question, there will be more MVP would like help you, and I will also check it when I free. – Leo Liu Nov 09 '18 at 16:01