New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files and folders generated during publish aren't copied from wwwroot to output #5498

Closed
damienpontifex opened this Issue Jan 28, 2017 · 21 comments

Comments

Projects
None yet
@damienpontifex
Copy link

damienpontifex commented Jan 28, 2017

Steps to reproduce

See sample project for reproduction here https://github.com/damienpontifex/NotPublishingGeneratedFiles

<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
    <Exec Command="npm install" />
    <Exec Command="npm run build" />
</Target>

npm build script

"scripts": {
    "build": "tsc"
}

tsconfig.json has the property outFile = wwwroot/ts/app.js

PrepareForPublish compiles typescript into wwwroot/ts folder.

This folder is also removed on dotnet clean and ignored by git

Steps to reproduce:

  1. dotnet restore
  2. dotnet publish -c Release -o <your output dir>

If you re-run the publish step, the files are appropriately copied as they existed at the time the publish was started.

If you run dotnet clean to clear away generated files and re-run publish step, they are again missed when copying to output as per original restore and publish.

I have also tried changing the PrepublishScript target value of BeforeTargets to ComputeFilesToPublish from looking at targets here https://github.com/dotnet/sdk/blob/master/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Publish.targets but with no success

n.b. If I generate the files into a folder that does exist and has content (e.g. wwwroot/js has site.js in it) then the copy works fine. It's only if I generate both a new folder and the files inside it in this step

Expected behavior

Files generated into wwwroot to be in output directory under wwwroot

Actual behavior

Files are generated in source wwwroot folder, but not copied into publish output wwwroot folder

Environment data

dotnet --info output:
.NET Command Line Tools (1.0.0-rc3-004530)

Product Information:
Version: 1.0.0-rc3-004530
Commit SHA-1 hash: 0de3338

Runtime Environment:
OS Name: Mac OS X
OS Version: 10.12
OS Platform: Darwin
RID: osx.10.12-x64
Base Path: /usr/local/share/dotnet/sdk/1.0.0-rc3-004530

@nil4

This comment has been minimized.

Copy link

nil4 commented Jan 28, 2017

I share the same concern. Is there any guidance on how to hook up tasks (e.g. Typescript, Webpack, etc.) to run during CLI builds, such that their output is picked up by the build/publish process?

@livarcocc

This comment has been minimized.

Copy link
Member

livarcocc commented Jan 28, 2017

@nguerrera @dsplaisted Any chance that the published files are being calculated before the tasks in the prepublish target run?

@armartinez

This comment has been minimized.

Copy link

armartinez commented Jan 29, 2017

I have the same issue with this prepublish task

<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish" Condition=" '$(IsCrossTargetingBuild)' != 'true' "> <Exec Command="npm install" /> <Exec Command="bower install" /> <Exec Command="gulp clean" /> <Exec Command="gulp min" /> </Target>

@dsplaisted

This comment has been minimized.

Copy link
Member

dsplaisted commented Jan 29, 2017

Any chance that the published files are being calculated before the tasks in the prepublish target run?

Yes, the content items from wwwroot are calculated during evaluation before any targets are run.

@damienpontifex @nil4 @armartinez As a workaround, you can add this target to your project file:

  <Target Name="AddGeneratedContentItems" BeforeTargets="AssignTargetPaths" DependsOnTargets="PrepareForPublish">
    <ItemGroup>
      <Content Include="wwwroot/**" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);@(Content)" />
    </ItemGroup>
  </Target>

@mlorbetske @vijayrkn Should we consider adding something like this to the Web SDK so that files added to wwwroot by npm tasks or similar get included in the publish output?

@nil4

This comment has been minimized.

Copy link

nil4 commented Jan 29, 2017

@dsplaisted thank you for suggesting this workaround! Unfortunately I found it to kick in during every build in Visual Studio, which would slow down development significantly.

My use case is a Webpack task that should run after the C# Web project is compiled, but only before it's published; the publish output should pick up the files generated by the Webpack task in wwwroot/dist.

I cobbled together something to unblock myself for now, through a painful half-day of running dotnet publish with diagnostic verbosity to figure this out. This feels fragile and I'm sure a future update would break it. I am hoping for a better solution and thus 👍 to adding something supported to the Web SDK.

Here is the task I used in case someone else finds it useful:

<Target Name="RunWebpack" BeforeTargets="PrepareForPublish">
    <Exec Command="npm run webpack:bundle" />
    <ItemGroup>
       <!-- Inspired by https://github.com/aspnet/JavaScriptServices/blob/0200489bfcbf66c35c17c549498fb122ec9edd56/templates/AureliaSpa/Aurelia.csproj#L72 -->
       <_WebpackFiles Include="wwwroot\dist\**" />
       <ContentWithTargetPath Include="@(_WebpackFiles->'%(FullPath)')" RelativePath="%(_WebpackFiles.Identity)" TargetPath="%(_WebpackFiles.Identity)" CopyToPublishDirectory="Always" />
    </ItemGroup>
</Target>

@TheRealPiotrP TheRealPiotrP added this to the Discussion milestone Feb 1, 2017

@TheRealPiotrP

This comment has been minimized.

Copy link
Contributor

TheRealPiotrP commented Feb 1, 2017

Moving to 'discussion' milestone. This isn't really a CLI issue but I don't want to reset the conversation history.

@mlorbetske

This comment has been minimized.

Copy link
Member

mlorbetske commented Feb 1, 2017

@damienpontifex

This comment has been minimized.

Copy link

damienpontifex commented Feb 1, 2017

@piotrpMSFT would this be more appropriately re-raised on aspnet/websdk as linked by @dsplaisted ?

@vijayrkn

This comment has been minimized.

Copy link
Collaborator

vijayrkn commented Feb 1, 2017

Yes, we should be able to add something like this to the websdk to handle files generated inside wwwroot

#5498 (comment)

@damienpontifex - Can you create a bug in the https://github.com/aspnet/websdk repo?

@livarcocc

This comment has been minimized.

Copy link
Member

livarcocc commented Feb 7, 2017

Closing this, since it is being tracked in the aspnet/websdk repo.

@JasonRowe

This comment has been minimized.

Copy link

JasonRowe commented Mar 20, 2017

Could we put this work around in the xproj to csproj conversion docs?

@livarcocc

This comment has been minimized.

Copy link
Member

livarcocc commented Mar 20, 2017

@mairaw for the conversion docs.

@dsplaisted

This comment has been minimized.

Copy link
Member

dsplaisted commented Mar 21, 2017

I think the web SDK is intending to add a target so this doesn't happen.

@JasonRowe

This comment has been minimized.

Copy link

JasonRowe commented Mar 22, 2017

Good examples of running webpack only before publish and not every build.

update 9/29/2017 - example moved to templating
https://github.com/aspnet/templating/blob/95f2b8d375256ca7057cbe88dcbfff644697f183/src/Microsoft.AspNetCore.SpaTemplates/content/Vue-CSharp/VueSpa.csproj

@t0xicDen

This comment has been minimized.

Copy link

t0xicDen commented Sep 13, 2017

Who still has similar issue try to read my comment

@VictorioBerra

This comment has been minimized.

Copy link

VictorioBerra commented Sep 27, 2017

@JasonRowe 404 on that. Also how do you properly debug if you only copy Gulp/Grunt/Webpack/NPM compiled assets out on a publish?

@alasdaircs

This comment has been minimized.

Copy link

alasdaircs commented Oct 6, 2017

@VictorioBerra WebPack has its own webserver - we do all the dev & debugging on that with live-reload. The release Gulp is only required on publish, and we publish to test or staging.

@blteblte

This comment has been minimized.

Copy link

blteblte commented Sep 11, 2018

Is there a solution for ASP.NET project for exactly the same issue?

@dsplaisted

This comment has been minimized.

Copy link
Member

dsplaisted commented Sep 11, 2018

@blteblte This is supposed to be fixed for ASP.NET Core projects, if you are having a similar problem please file a new issue.

@blteblte

This comment has been minimized.

Copy link

blteblte commented Sep 12, 2018

@dsplaisted Sorry. I was not clear enough - I meant ASP.NET Web Application (.NET framework) project - not core. I know this is not stack overflow, but this seems the only place the problem is recognized.

But nvm - found how to hookup stuff generating files before publish (so publish picks it up) anyways

@vijayrkn

This comment has been minimized.

Copy link
Collaborator

vijayrkn commented Sep 12, 2018

@blteblte - Can you share a sample csproj? csproj should have an entry for the files that needs to be publishes since the non core project system does not support globs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment