Hi everyone, I have the latest version of dotnet
from the README page (rc2/preview1) and I'm wondering how to copy files to the publish directory post-build. The reason is I'm looking to change the version of mscorlib that's used with my app (see dotnet/coreclr#4678) by overwriting the files included with Microsoft.NETCore.App
with my copy, as I am contributing to coreclr/corefx.
Anyway, here is my project.json file thus far:
{
"buildOptions": {
"copyToOutput": {
"include": "../../git/coreclr/bin/Product/Windows_NT.x64.Release/**"
},
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": "1.0.0-rc2-*"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"System.Linq": "4.1.0-rc3-*",
"System.Runtime": "4.1.0-rc3-*",
"System.Threading.Tasks": "4.0.11-rc3-*"
},
"imports": [
"portable-net45+win8",
"dnxcore50"
]
}
},
"runtimes": {
"win7-x64": {}
}
}
copyToOutput
doesn't seem to be working here; instead, it seems to be reproducing the files in <app>/bin/Release/git/coreclr/...
, which is not the effect I intended.
I also know you can do something like have "scripts": { "postpublish": {
and run shell commands from there, but I'm planning to build this app on another machine, so doing something like
"scripts": {
"postpublish": [
"xcopy ../../git/coreclr/bin/Product/Windows_NT.x64.Release/* %publish:OutputPath%"
]
}
would work on Windows but not on Linux, if I understand correctly. (It would be nice if we were able to run different shell commands depending on the host OS, e.g. xcopy
on Windows and cp
on the latter.)
So basically, is there any way to get this done from the project.json
and have it work on any OS? Thanks.
@jamesqo When you speak of copying assets over at publish, that's all in publishOptions
now. I'm not sure if it will suit your needs, but the structure is like this if you're just trying to get assets put into the output. In my case, I use it to move the Views
, wwwroot
, and Logs
(with a dummy text file in the folder, as there is a bug right now that won't copy empty folders) over to the published output. If this works for your scenario, you won't need special tooling at all.
"publishOptions": {
"include": [ "Views", "wwwroot", "Logs" ]
},
If that doesn't suit your scenario and you need to do more complex work with the files (use logic to determine what needs to be moved/modified); instead of relying on a platform-specific command like xcopy
or using publishOptions
as shown above, have your postpublish
be an actual .NET Core portable application that will run on any supported platform.
True, you would have to build such a thing for your purposes, but at least there are samples out there. In my case, I took @moozzyk publish-iis
tooling locally (a clone of https://github.com/aspnet/IISIntegration/tree/dev/src/Microsoft.AspNetCore.Server.IISIntegration.Tools), made the changes I wanted (including converting it over into a self-contained .exe
app), and I use that as my postpublish
tool ("postpublish": "guardrex-publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
) ... it's just another .NET app as far as my project is concerned. In your case, you would want that to be a portable app so that it would run anywhere ... and perform whatever postpublish
actions you need to take.
They gave us a lot of cool toys :rugby_football: to play with! :smile:
Using xcopy in the postpublish script works fine in command-line but it seems nothing happen while publishing with Visual Studio 2015.
Same for postcompile script.
include
can no longer copy directories with the new .csproj
MSBuild project format. What can I do instead?
I have a post publish approach that works with empty folders. see ... https://github.com/GuardRex/testselfcontained_caching/blob/master/testselfcontained.csproj
Thanks @GuardRex
This may not be right place to ask this question. I just want to know. After publishing, what files should I copy to my shared hosting provider?
@initiative Copy over the contents of the publish folder.
Sorry @smithaitufe ... my phone got me when I was typing your name. :grinning:
@GuardRex Lol. It is okay. I figured it out through trial and error. However, after copying the files to the root folder of my domain
dl.gov.ng\library.dl.gov.ng\tu.library.dl.gov.ng\
I decided to test it in the browser. So I typed
tu.library.dl.gov.ng
and I got error.
Server Error in '/' Application.
I don't the cause though.
I have changed the framework to: No Managed Code.
From what I read in this (post)[https://docs.microsoft.com/en-us/aspnet/core/publishing/iis],
I have to create a virtual directory that points to the file containing the published files.
I am lost there.
Your help is appreciated.
publishing/iis
Yep! You came to the right place ... I wrote that one with [@]Rick-Anderson. :smile:
We have a few other related docs there, too, which help explain other aspects of hosting on IIS. Check out the ASP.NET Core Module configuration reference and the Directory Structure doc, which explains a little more about the published files and folders.
In IIS, point the website physical path directly to the folder where the app resides. This will be the folder where the web.config file exists. If you look in the web.config you'll see that it configures the ASP.NET Core Module (ANCM) to either run the app directly (processPath=".\myapp.exe"
) for a self-contained deployment (SCD) or run it via dotnet
(processPath="dotnet" arguments=".\myapp.dll"
) for a framework-dependent deployment (FDD). The ANCM will then setup the reverse proxy through IIS to the Kestrel server in the app. You can get more info on those two types of deployments at .NET Core Application Deployment.
Definitely check out the Troubleshooting section of the Publishing to IIS doc, where we talk about turning on stdout
logging for an app that won't startup properly. The list of Common Errors cover most of the common problems in setting up the reverse proxy. Basically, you'll look at the Application Log (Event Viewer), the stdout
log entry (if any), and the behavior in the browser and compare to the errors in the list. [EDIT] ... and forgot to mention, make sure that before you get too deep into troubleshooting IIS that you run the app directly on Kestrel to make sure that the app itself isn't broken.
If you need live chat help, visit with the devs in the Slack Team Room. You can self-signup at http://tattoocoder.com/aspnet-slack-sign-up/. I'm in there sometimes, but you'll find devs there with experience getting ASP.NET Core apps running on IIS who can help. There is an #iis channel, but you can ask right in the #general channel.
@GuardRex
WOW. Thanks so much. I am so glad about the slack room. I have enjoyed this type of team work using Elixir and Phoenix.
Thanks for helping me with this nice intro write up. So let me get something clear
I am not sure of this but let me continue
Will those be valid steps?
Virtual directories are not supported. You'll prob need to setup a 301 redirect using the URL Rewriting module in IIS or the URL Rewriting Middleware. So it goes like this ...
Setup a folder to hold the site (the published assets described in the Directory Structure doc).
Point the IIS website physical directory (in Basic Settings) directly at it. Setup your binding to the hostname (in Bindings). The URL Rewrite should look something like this, which just removes the folder from the path ...
... you can do it with the URL Rewriting middleware as well. It's probably faster for your site visitors if you use the IIS module.
@GuardRex
Please is it possible for us to do a skype call so you can guide me through?
I intend to share the screen with you because I am not able to do it successfully.
Thank you so much for your time.
@smithaitufe I don't use Skype, and my employer wouldn't allow me to use it anyway. I suggest speaking with the devs on Slack chat (self-signup at http://tattoocoder.com/aspnet-slack-sign-up/ ).
If Slack devs can't help and you're having a problem getting the app to run (i.e., it won't even run on Kestrel), ask about the error in the Home repo issues, and it can be helpful to troubleshoot an app if you put up a repro project on GH that demonstrates the exception(s) you're seeing.
If Slack devs can't help and the app runs ok on Kestrel but you can't get it to run on IIS, open an issue in the IIS Integration repo issues for help from the dev team. Provide as much description as you can with your IIS configuration ... screenshots and details (like you posted above) are a big help to understanding what you're trying to do. If the application or the ANCM is throwing error(s) in the Application Log (Event Viewer) or the stdout
log, of course include those in your issue.
Certainly if you discover a knowledge gap in the documentation, you can open an issue at the ASP.NET Core doc issues or the .NET Core doc issues, depending on which doc set should address the knowledge gap.
Most helpful comment
include
can no longer copy directories with the new.csproj
MSBuild project format. What can I do instead?