Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

Client-side asset generation before PrepareForPublish not getting published #1017

Closed
svallis opened this issue Mar 13, 2017 · 3 comments
Closed

Comments

@svallis
Copy link

svallis commented Mar 13, 2017

I posted this on SO at first but haven't had any responses. Reposting here in the hope that somebody can shed some light on what is going on.


I have a gulp publish task which prepares assets for the production server during the publishing process. On project.json this was working successfully:

"scripts": {
    "prepublish": [ "npm install", "gulp publish" ],
    "postpublish": [
      "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%",
      "dotnet razor-precompile --configuration %publish:Configuration% --framework %publish:TargetFramework% --output-path %publish:OutputPath% %publish:ProjectPath%"
    ]
  }

Migrating via VS2017 to MSBuild with a csproj gives what I expected to be equivalent as:

  <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
    <Exec Command="npm install" />
    <Exec Command="gulp publish" />
  </Target>

Whilst the npm install and gulp publish commands are executed, it seems like they run too late to have the assets they produce get included in the actual publish process.

If I freshly clone the repository and publish twice in a row the second one is successful, as the assets were generated from the first publish and therefore included in the second publish.

My first thought was to jump earlier in the publish process by setting BeforeTargets="Build" but not only did this also not work, but even if it had we'd be running these commands on every single build, even during development. It's as if the publish process takes a snapshot of the file-system when beginning and does not check for files added to the file-system anywhere during the publish process. For this project, we need to be able to build from a freshly cloned repository as that's what happens on the build server (git clone -> dotnet restore -> dotnet publish -c Release -o PublishOutput).

What does work is setting BeforeTargets="Restore". This generates everything perfectly on the build server, presumably as the assets generate by gulp publish existing within the file-system before the dotnet publish command. Of course, we don't want to actually generate the assets on every single dotnet restore!

Is there a way to hook into a target that is earlier than "PrepareForPublish", or does anybody even have a list of MSBuild Targets that you can latch onto? The documentation helpfully points out that MSBuild "supports many ready-made targets" with no list.

@nil4
Copy link

nil4 commented Mar 13, 2017

@svallis This is tracked by https://github.com/dotnet/cli/issues/5498 and https://github.com/aspnet/websdk/issues/114. I am using a workaround (details here) until a better solution is provided out of the box.

@svallis
Copy link
Author

svallis commented Mar 13, 2017

Thanks very much @nil4 - did search but the issue is being tracked in repos I didn't check, appreciate the heads up!

@mlorbetske
Copy link

Closing this here since it's tracked elsewhere

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants