Directory not published - asp.net

I have a little problem and I don't find any solutions.
In my asp.net web application, I have a directory in the solution with some xls files.
When I make a publication, I hoped that the directory is in the source files rendered. But the directory isn't there and I have to copy/paste it manually.
The problem is that I forget to do it regularly. Can I tell to visual studio to add this directory to the sources?
Thanks for help.

Right click on the files in Solution Explorer and select Properties. Then in the Properties grid, set the build action to Content. This will copy the files to the build output.

Related

Visual Studio 2015 Ignoring New Folders & Files

When I add a folder to the visual studio project, it ignores it completely. It didn't do that until recently, and I am not entirely sure why this is. A clean build does not solve the problem, in the visual studio folder structure, the resources folder is present.
And in the latest build it is completely ignored.
To show it is not exuded from the project:
If the files are missing on a build server check the files are committed to your source control.
If the folder is empty, its not clear in your question if it is or not, you can either add a dummy.txt file or follow the instructions listed here. How to force MSBuild to copy empty folders in project?
If the files are missing from a publish you need to select all the files you want to publish, and change the "Build Action" to Content.
You cannot directly select a folder, you need to select the individual files.
Interesting post about the different options for build action:
What are the various "Build action" settings in Visual Studio project properties and what do they do?
Side Note
If you want your files to be published to the output direct on build. I.E. the bin folder. Then set the "Copy to Output Directory" to copy always or copy if newer.
Not sure why you would want to do this for css files though.
In the Visual Studio Solution Explorer right-click on on each files under resources folder and
select Properties > set build action to content.
I had to click the show all files button below the "Solution Explorer" text to see that I wasn't including anything.

Use script files from another project inside same solution

I'm trying to use some script files between different projects. I have one solution with four projects. In the project "A" I have some scripts like Jquery, Javascript Plugins, etc, and i want to use them on the project "B", by adding a scriptmanager, or anything that works. What can i do this?
I'm using Visual Studio 2010.
Here is a printscreen with my environment.
[EDIT]
Hello, after doing what #CStick says, a have now the scripts in my other project, so a can't add them to a ScriptManager. The problem is path not found on Asp.net code. It cant find the script cause they're placed in the other project. What can i do to solve it?
I know this is old, but for future reader i post an answer.
You will have to use "Link project file" for this.
From the target project, right click on the folder you what the file to be
Select add -> Existing file
Browse to the file you need then click on the arrow at the right of the add button and select add as a link
After this you can modify the file in booth project, but the fille will be only in the source physical location until you publish the project.
This can cause problem for client side file, like script file, on debug because you cant view the file because it's not physically in the target project.
You can use MsBuild to copy the source file on the target directory on build.
(See this answer)
In short, you will create a .targets file then add a reference in your project file.

Publish of application fails to find file that exists

I've run into this issue when trying to publish my application today that I have published many times before. I'm trying to publish to a directory.
The issue I have is, if I go to my app directory C:\www\clients\clientsite\app\clientproject\Properties\PublishProfiles where the error below says it can't find the file I can clearly see the git.pubxml file.
Copying file Properties\PublishProfiles\git.pubxml to obj\Release\Package\PackageTmp\Properties\PublishProfiles\git.pubxml failed. Could not find file 'Properties\PublishProfiles\git.pubxml'.
I've checked directory security settings and those are proper. I tried deleting my bin and obj but nothing is making a difference.
Often times the solution here is to edit the project file itself in notepad.
The trick to finding the afflicted path is to inspect the OUTPUT window, not the ERROR LIST window.
Once you find the afflicted file path, search for it in the project file and remove the reference.
In most cases the troublesome lines in the project file look like :
<Content include="{your path}" />
Continue to remove the includes until publishing works.
IMPORTANT: if you keep Visual Studio open while you're doing this, you must accept the "reload all" prompt.
I just ran into this after removing all unversioned files from my filesystem (which caused some .pubxml.user files to be lost.
If you right click the project node and click "publish", then select the publish profile that is causing problems, then simply close the publish dialog, Visual Studio will ask if you want to save changes... when you click yes, it regenerate the .pubxml.user file and everything works again.
Have you ensured that the file actually exists in the project? I have had problems working in a team where some file I wrote ended up not appearing in VS as a project file, so when we published, it didn't exist in the publish. If you can't find it inside VS, ensure that you are not debugging, and drop the file into the project file structure, then publish as normal.
VS was saying it couldn't find that file because the git.pubxml file in that directory was of type USER File and it needed to be PUBXML. When I added the correct file type from another version of that same project, I was able to publish the project again. I believe the PUBXML file was removed by mistake in source control.
It usually happens to binary files after updating it. Some packages remove it's own .xml and .pubxml files, while visual studio still believes that it is a part of the project.
What you need to do it to check for a Yellow Triangle besides the file name in the project directory tree, and remove that files, they're useless since your project compiles without errors.
try changing the publishing settings. if you check "Precompile during publishing" this will recreate your .pubxml.user file
I looked in Solution Explorer under the PublishProfiles section and found that the file was excluded and had a "!" by it showing a warning that the file wasn't found. I deleted it, then went into my Publish settings to edit a profile. I changed something (for me to compile files during publish.) Then I tried republishing the solution, and it worked!

Question On Temporary ASP.NET Files

Have a question on "Temporary ASP.NET Files" folder; I have bit knowledge on what this folder is for as outlined by another thread in this forum
What is the "Temporary ASP.NET Files" folder for?
But recently, I am getting a warning while trying to build my new project as below
'c:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\some folder\filename.cs' conflicts with the imported type ... using the one ...
Looks like that, two copy (shadow copy) of the same class (.cs file) file exist in two different version of temp folder and hence it's confusing as to use which one.
My Question is: Shall I go ahead and delete all contents from "Temporary ASP.NET Files" folder? Is there any side affect if I do so? Please let me know.
Thanks,
Rahul
If you close all of your instances of VS 2005, you can delete all of the files/folders within this folder. This folder is exactly as it's named -- Temporary. It loads all of the instances of your compiled files as they enter memory when they're loaded for a website. When you perform a "clean" on your solution it is supposed to empty the files in the folder relating to your open solution.
If you empty out your files and you continue to have this problem, then the problem will be related to how you have referenced projects and third party libraries within your solution.
If you take now your project, put it in a zip and send it to a friend, than he doesnt have the temporary folder for that project, and can build it too... So your main stuff should be in the project directory itself. Have you everything saved properly? Than close your Vs and clean the mess. (99% sure)
Have you tried to Clean your solution/project and recompile? That would only remove the compiled/temporary files associated with that project.

"Add as Link" for JavaScript files returning 404 in debug

Using a Visual Studio 2010 ASP.net web application, I have several projects that share some JavaScript/css files. The most logical way for them to share these files is to place the files in a single folder and each project has them included with the "Add as Link" option. However, if I add the files this way when I'm debugging using either the Visual Studio Development server or debugging using a local IIS web server all requests for these files return 404 Not Found errors. If I publish the site then the files are copied but that obviously doesn't help with debugging.
Is there something I'm missing or is this a failing on VS's part?
To overcome this problem some time ago I created a 'MSBuild.WebApplication.CopyContentLinkedFiles' nuget package. This package adds MsBuild target which copies all content files added as link to project folder during build.
Note: if you use source control then it is better to add copied files (from Web Application folder) to ignore list.
I wouldn't really call that a failing, since you asked for that behavior in the first place: linked items in Visual Studio projects are actual links to external files. Those files can reside anywhere on the disk and are not copied into the project folder.
You might want to copy those files locally yourself during a pre-build event. That way, the files will remain synchronized and you won't duplicate them until your first compile.
The problem seems to be that the website runs right from your source folders, rather than from the bin folder. This means that the file will be missing, whether or not it is copied to the output folder.
It's probable that running from a local or remote web server would not have this problem, though I didn't get that working, and I'd rather not add IIS to my local machine if I don't have to.
Adding a pre-build copy command did work. Note that the current directory will be the bin folder. (You can use cd to echo the current directory to the build window if you want to see it):
If the file is in another solution, your command will look something like (three ..s: one to get out of each of bin, project, and solution folders):
copy ..\..\..\OtherSolution\OtherProject\Scripts\MyJSFile.js ..\Scripts\
If it's in the same solution, but a different project:
copy ..\..\OtherProject\Scripts\MyJSFile.js ..\Scripts
One minor issue is that the link to the file will collide with the new copy of the file, even if you don't add it to your project. As long as you make the link first, it seems to work. If you copied the file first, you'll have to manually delete the copy, and then refresh the solution explorer before before being able to add the link.
Select the link in Solution Explorer and then look at properties window and set Copy To Output Directory to Copy Always. Linked items are set to Do Not Copy by default.
BTW, you can copy many files as links very easily directly from Solution Explorer when using VSCommands 2010 extension.
See this blog post about a simple addition to your project file.
http://mattperdeck.com/post/Copying-linked-content-files-at-each-build-using-MSBuild.aspx

Resources