westonwalker / SparkPoc

48 stars 8 forks source link

How to Folder Publish after Vite has been added to the solution? #1

Open theKingdomAge opened 9 months ago

theKingdomAge commented 9 months ago

I am using Visual Studio 2022 Preview. When I run the site in debug mode it works/displays as it should. But if I Publish it to a folder to use with IIS the .js and .css files are not found.

The same problem can be reproduced running in debug mode by going into the .env file and changing ASPNETCORE_ENVIRONMENT=Development to ASPNETCORE_ENVIRONMENT=Production

I am new to Vite and haven't found the solution to this yet.

Thanks for your help/time

theKingdomAge commented 9 months ago

Here are my steps I used to get a Folder Publish to work with IIS. I named my app SparkTest3 and used the default Sqlite database.

In Visual Studio right click on the project SparkTest3 and select Publish from the menu Select Folder from the next menu Click Next Make a folder one folder back from the code and name it Publish Copy and paste the Publish path into the Folder location target field Click Finished Click the Publish button

In IIS add a new Web Site with name = local.SparkTest3.com Application pool = local.SparkTest3.com Physical Path = (the path to the publish folder) Binding settings: Type=http IP Address = All Unassigned Port 80 Hostname = local.SparkTest3.com Click Ok button to finish adding new Web Site

White still in IIS go to the Application Pools and find local.SparkTest3.com Double click on it and change the .NET CLR version to "No Managed Code" and click the Ok button.

Edit the C:\Windows\System32\drivers\etc\hosts file and add 127.0.0.1 local.SparkTest3.com

Now load http://local.sparktest3.com/ in your browser

Note it doesn't work yet - we have more to do. If you go to Event Viewer - Applications you see a .NET Runtime error and it says to check your .env file. If you check the Publish folder we don't have a .env file so we copy the .env file from the Code folder into the root of the Publish folder. Also copy the spark.db to the Publish folder.

Open the .env file in the Publish folder and change the following: APP_NAME=SparkTest3 (you don't really need to change this one at all, but since we are here, why not) ASPNETCORE_ENVIRONMENT=xxxxDevelopment (anything but Development)

Save the .env file and try loading the website in the browser It should load now but doesn't look right. CSS and JS is missing. Move or copy the \Publish\wwwroot\build\assets folder to now be Publish\wwwroot\assets

Try loading the site again in the browser. The website should look proper now with CSS and JS included. Try to login as the same user you created when running in Visual Studio. If it doesn't work then copy the sqlite.db file again from the Code folder.

Try to update your Profile. Change your name and click Update. Or try to make a new user account. You will find it isn't working. The problem is that the IIS Application Pool doesn't have write access to the sqlite.db file. We can fix that. With File Explorer go to the Publish folder and right click it and select Properties then select the Security tab then Advanced button then the Add button then click the "select a principal" link then in the textbox type or paste iis apppool\local.sparktest3.com
Click the Ok button Click the "Full Control" checkbox and then the Ok button and then click the Ok button and we are done.

Try updating your profile or adding a new account and it should all work now.