ASP.NET Setup Project - how to include static files not in VS? - asp.net

I am working on an ASP.NET MVC web application, and am working on the Web Setup portion. We are using SVN for version control. One of the issues is that the we are currently having is that the web designers modify and add a lot of html, css and js files that end up in the Content folders, but they don't add them to the VS project, so the new files don't get included in the installer.
One option is that we have to try to teach them to always go into VS and manually add the files, but we're on a large project and it's getting down to crunch time, so trying to get people to learn something new in a technology that they don't know will result in too many mistakes, so I'd like to work around that if possible.
Is there some way to get the setup project just to include files from a folder on the file system, instead of a project's designated content files?
Thanks!

I think I've figured it out:
Make sure that the installer project includes the Content Files for the web app. Then go into the web app's csproj file with a text editor and find the ItemGroup where the static Content files are listed. Then add an entry with a wildcard in it and the installer will package them in.
<ItemGroup>
<Content Include="Content\test.html" />
<Content Include="Content\*.html" />
<Content Include="Content\*.gif" />
<Content Include="Content\*.css" />
<Content Include="Content\*.jpg" />
<Content Include="Content\*\*.js" />

Right click on the folder in the File System view of the Web Setup project, and select Add, File...
It doesn't look like you can add an entire folder this way though, so you would have to add every file individually to the Setup program.
EDIT:
Aren't all files from your project folder included in a WebSite project in Visual Studio? Then it's just a case of having your WebSite project and Web Setup project in the same solution, then right-click on the Web Application Folder in the Web Setup project, select Add, Project Output... and then select the WebSite Project in the drop down and Content Files from the list box and click OK.

Unfortunately I don't think there is an out of the box way to do this, as projects maintains references to the files individually.
You could achieve what you need via a custom macro, or asking your other team to edit the .csproj XML file (perhaps simpler or riskier, depending on their background).

Related

ASP.NET 4.7 - Subfolder inside Content not deployed to cloud

I have just deployed my first ASP.NET 4.7 Application to Azure but on the deployed website the background image is missing. The background image loads without problem on local server and it is located in /MyApplication/Content/Images/bg.jpg.
I tried to log on to Azure console and found that in fact the entire Images folder is not uploaded (but the other files in the Content folder are there).
How do I include the Images folder when deploying to Azure? Is there some settings that I need to adjust during deployment or codes that I need to change in my Application?
Thank you.
After reproducing from our end we have observed that in order to make the folder content visible it needs to hold some files. We have manually added files by navigating through folder explorer but couldn't able to see any file being added in VS. So after adding the below lines to .csproj we could able to see the folder and its contents being added after deployment.
<ItemGroup>
<Content Include="Content\Images\**\*" />
</ItemGroup>
RESULT:
REFERENCES: How to include custom folders when publishing a MVC application?

Image not displayed when run ASP.NET directly from Visual Studio

I built an ASP.NET MVC web application from template in Visual Studio 2019. I have copied some .png files into a new folder - images - and copied it underneath my project folder.
I modify my .cshtml file added in <img src="~/images/img1.png" />, but when I run directly from the IDE, the image does not show up. Why?
I have tried below
copy images folder to different places, such as App_Data, Content, Views
Change the cshtml to be
<img src="~/Content/images/img1.png" />
<img src="~/images/img1.png" />
<img src="~/img1.png" />
<img src="img1.png" />
I also tried to change the property of the file
Build -> Resource
Copy to Output -> Always
None of them works.
Help!
You can do following steps in order to resolve your problem:
1) First you need to check if the files copied in new folder are included in your project. If not then, in visual studio, right click your files and select include into the project.
2) Secondly, you can check into the browser console which you will find in developer tools of the browser. Then you will be able to find out the root cause of the problem..

ASP .Net Core 2.2 publish to Azure

I am new to working with Azure, but recently I have published my ASP.Net core 2 app to App Service and cannot access Email templates (.html) from within the API.
API works fine, it connects to the client side and to the database, but when I try and send out an e-mail - I get exception:
Could not find a part of the path 'D:\home\site\{ProjectName}\EmailTemplate\template.html'.
From within the code I call template using the following path format:
../{ProjectName}/EmailTemplate/template.html
How do I access these templates on a hosted environment?
Many thanks,
Alex
As per comments.
Right-click on the html template in vs and click Properties, then change Copy to Output Directory > Copy Always.
Also, as #jpgrassi noted, you can also add patterns in your csproj file to include a whole directory or even all files that end with .html. Just right-click on your project and select Edit <Project Name>. Then just add this:
<ItemGroup>
<Content Include="EmailTemplate\*.html" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

Visual Studio 2012 Website - Make Project Folder Mirror Explorer

I'm guessing there's a standard way to do this that I never learned... I have a VS solution with some folders in it, you know, Models, Views, Controllers, etc. I added a few custom ones like Styles, Scripts, and Images. Naturally, I started saving images for the site in the Images folder in Explorer that VS created. I was sad to learn, however, that these files don't just show up in my solution, therefore they don't get Web Deployed either. Bummer. What is the right thing to do here?
P.S. Some of you probably jumped when I said I made a Scripts folder. I know about the built in minification stuff, and I don't want to use it at this point. Thanks.
If you don't mind getting your hands dirty in the .csproj file, firstly remove any existing file references from the Images folder of the project and then insert this before the <Import> tags.
<ItemGroup>
<Content Include="Images\**\*.*" />
</ItemGroup>
This will automatically include all files contained in the Images folder and its subfolders when the project is loaded.
Click Show All Files in the toolbar on top of Solution Explorer.
You can then right-click a file or folder and click Include in Project.
You also need to make sure that the files' Build Action is set to Content, but that should happen automatically.

Elimination of Aspx pages during Publish

I need to eliminate .apsx pages for my application for different locations basically.
How can I eliminate those pages during Publish time?
I have seen by making pages to Build Content to none. Is there any other alternate
solution?
Regards,
Sachin K
I would suggest using Web deployment project and follow these steps:
Add your WDP (web deployment project).
Right click on it and click on Open Project File.
in the wdproj file you will see a tag called <ItemGroup>.
Inside this tag add the following line:
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\FolderName\**\*.*" />
Save and close your wdproj file and that’s it.

Resources