Web project migrated from VS2013 to VS2015 cannot be published - c#

I had an Asp.Net MVC project, in VS 2013 update 4, and now I continue working on it in VS 2015. The Asp.Net version is not upgraded, i.e. I still use the stable asp.net 4 and MVC 5. The problem is: I cannot publish this project anymore. During the publish, it complains about xml files of every library I use, like EF, OWIN, ... both for Nuget libraries and normal .net framework libraries.
I tried adding these xml files from other sources and the publish proceeds further, but it raises another error like this:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(2991,5): Error : Copying file obj\Release\Package\PackageTmp\Content\bootstrap-rtl.min.css to obj\Release\Package\PackageTmp\obj\Release\Package\PackageTmp\Content\bootstrap-rtl.min.css failed. Could not find file 'obj\Release\Package\PackageTmp\Content\bootstrap-rtl.min.css'.
I removed this file from the project and the error still refers to this file. I searched the solution folder for this name, both in file names and file contents and I don't have it anywhere. It seems that Visual Studio has cached the publish procedure somewhere and does not update it when the project changes.
Any hints or solutions?

In our case the solution was to create a new clean project, then copy all source code files (C# code, javascript, css, razor templates, html, ..., but not for example, contents of bin and obj folders) from the old project into the new one, and then adding them to project (in solution explorer).
Don't waste too much time on solving this problem, dodge it.

Related

Why Visual studio 2017 is publishing entire solution?

Installed VS2017 from scratch and moved existing vb.net, c# webform solutions to the new laptop.
First issue was related to "The target GatherAllFilesToPublish does not exist" error which I fixed by opening vbproj (or csproj on another project) and add this line:
<Target Name="GatherAllFilesToPublish">
</Target>
Now I was able to publish with no errors but the output in the destination folder is the entire solution including .aspx.vb or .aspx.cs files, .Global.asax.vb, .aspx.designer.vb files etc.
Checked the project Package/Publish Web settings and Items to deploy is set to "Only files needed to run this application".
Still the publishing copies the entire solution instead only the aspx, dll and only what is needed. Any idea what I am doing wrong ?
Edit csprojfile,in that file change vs version of your old project to vs 2015 in property group.save the file and rebuild .it will work properly.

VSIX Package and .NET5 project

I'm creating a VSIX project to read all the Config.xml files in the solution to generate many files within each project.
I'm having difficulty finding the Config.xml file inside a project and I believe it is because of the new Asp Net 5 project structure.
dte.Solution.Projects.Item(1) returns the "src" folder.
dte.Solution.Projects.Item(1).ProjectItems.Item(1).Name will return the project folder.
Then I cannot go any deeper inside the project because the item returned for the project is a ProjectItem and not a Project. ProjectItems do not have items.
How can I get a specific file in my project under asp net 5?
I am currently using a "Tools > Command" to execute the code. Would an project and/or xml file right click context menu fix this? If so how would I implement that?
Use the ProjectItem.SubProject property. See an example here:
HOWTO: Navigate the files of a solution from a Visual Studio .NET macro or add-in

.NET (Visual Studio) Share assets between projects

I'm working with Visual Studio. There I have a solution with several web-projects (.net MVC 4). All of these web-projects use the same javascript-libs. Currently I copied the library into each project, but this can't be the final solution. What is the best approach to share those library (assets in general) between all of the projects? Just link them? Or is it possible to create a project and reference it in all projects?
Update
"Link" the javascript files from another project is not a possible solution as I would have to link thousands of files (one of the libraries I am using is ExtJs) what makes it impossible to build a project without freezing visual studio...
Possible solution
Currently I have a (Web) MVC Project called "Web" and a (Class Library) Project called "ClientScript" which contains all the JavaScript files which are shared between several Web Projects. As linking all the needed JavaScript files is not a possible solution (because it's a matter of thousands of files what causes visual studio to freeze) I copy all the needed JavaScript files to the individual Projects using the Build Events in each Web Project (Project -> Properties -> Build Events -> Post-build).
My Post-build command line in the Web Project looks like this:
start xcopy "$(SolutionDir)ClientScript\Frontend\*" "$(SolutionDir)Web\Scripts" /r /s /i /y /D /E
Every time you build your Web Project all the changed Javascript files get copied from the ClientScript Project to your Web Project.
While developing the Javascripts I run a small "filewatcher" tool which automatically copies a file from the ClientScript Project to every Web Project when it changes. This way I don't have to build the Web Project every time when I make a change to one of the Javascripts.
Anyone that stumbles across this question here in the future should know that there are now Shared Projects in Visual Studio to solve this problem. Universal Windows projects use them by default and you can create your own by downloading and installing the VS extension here: https://visualstudiogallery.msdn.microsoft.com/315c13a7-2787-4f57-bdf7-adae6ed54450
Note: At this time they can be picky about what type of project you try to add the shared reference. I created a JavaScript shared project to share js files between a Windows store js app and an MVC web app and it would not let me do that saying they had to be of the same language. (It supports C#, C++, or JavaScript).
Place the JS files in a single folder, likely above all others, and add them to the project but use the "Link" option. It's part of the drop down on the "OK" button in the "Add existing item..." dialog.
When you run every new ASP.NET MVC 4 project it's take a new port then other app have take.
I simply suggest you a simple thing.
run a project which contain all the pacakages. open them webmatrix and run them as localhost:80.
You need to set the port in settings section of your site in webmatrix. Now it will rechable at localhost now you can reference all the libraries from this packages.
Slightly older thread, but I have another way of doing a similar thing using Web Essentials, that handles the issue of not publishing correctly.
I have a shared folder outside of the projects that require the shared file, normally a 'common' project with other things in as well, but can be just a simple folder as suggested by Michael Perrenoud.
However instead of 'Add as Link' I have been creating a new bundle in the project that requires the shared js/css file, with the same name as the shared file, and then referencing that file in the shared folder using a relative reference location rather than the root based one it starts with.
To add a file from a shared folder in the root of the solution to the scripts folder use the following code in a new bundle file (*.bundle), changing the folder/file names as required.
<?xml version="1.0" encoding="utf-8"?>
<bundle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://vswebessentials.com/schemas/v1/bundle.xsd">
<settings>
<minify>false</minify>
<runOnBuild>true</runOnBuild>
</settings>
<files>
<file>../../MySharedFolder/my-js-file.js</file>
</files>
</bundle>
Then every time you build it recreates the bundle with the latest version, this version is then also published as expected :)
You can even create a minified version if desired by changing 'minify' to true. Or better yet you can add them loads as a bundle too if you want, you have that flexibilty.
This is an older thread but due to complex business requirements these days applications are divided in to different modules or sub projects.Thus, brings us the need to share common resources like JavaScript files, themes and CSS style sheet files.
I personally feel that common files should be put in separate Asp .Net MVC 5 project which has following structure :ASP.NET MVC5 folder structure
Now the best part is you can separately manage the dependencies using Bower,NPM or Nuget package manager.
After you have organised all the files in this project host this project to your own CDN or may be on cloud. You can use Using CDN in Bundle Approach to get script or link references.
That will help you sharing common resources across all the projects.There us a short coming though if you have many developers on the team and if someone added incompatible version lib can affect all the apps.

How Do You Clear an ASP.NET app for compiling?

I have been building and rebuilding an ASP.NET program.
I made the horrible mistake, I think, of recently copying the published content back to the folder I was developing.
So now I have an unusual error when I build the code. It says That there is a duplicate definition in one file in a temporary directory with anohter file in a temporary directory.
Error 3
The type 'ChildEventHandler' exists in both
'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET
Files...\b90cc7a4\28d266b\assembly\dl3\c4cf1ea3\b6e4b808_ef7cce01\App_Code.DLL'
and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET
Files...\b90cc7a4\28d266b\App_Code.asx5jp5d.dll' C:\inetpub\wwwroot...\Resources\usercontrols....ascx.cs 11 18 C:......\
I removed project and file names, of course, but this is basically what the error says.
Since the error is with temporary files, what should I do?
I do not see a "clear" option in visual studio to clear out the files of a compile.
This problem I faced sometimes back while compiling. Go to this folder
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files and delete all the files and folder under it. When you build an application which is not hosted under IIS, temporary debug files and folder get created under this folder.
It may happen that you get an access denied error while deleting them. Close your Visual Studio solution and delete everything under this folder. It will resolve the compilation error.
For those using Visual Studio 2015 in Windows 8 or Windows 10, the solution is to remove all temp files from the following location:
%AppData%\Local\Temp\Temporary ASP.NET Files
and then rebuild your Solution.
In my case, the error is come from some cshtml files that are under project folder but not included in project. So if you search the error in entire solution, it couldn't be found. You can use show all files to show the not included files, and try to open them to find the possible files that cause the error.
If you haven't got the option of "Clean Solution" (maybe Express verions, or pre-2010 don't have this?) then, to fix this error, simply go to the /bin folder of your solution and delete all items, then Build again.
This will recompile all the DLL files.

For a Silverlight 4 Visual Studio solution, what needs to be in version control?

I have a Silverlight 4 app that I'm building with Visual Studio 2010. I'm using Mercurial/TortoiseHG to do version control. Which files do I need to check in? By default, it checks in all sorts of .dlls in /bin/debug and stuff. Do I really need those? Or can I just grab code and content files? Do I need to version something to keep track of project properties and references, or is that contained within the .csproj file itself?
You don't need to include stuff in /bin or /obj. This is true of all VS solutions in source control. These are recreated upon every rebuild. Also, for Silverlight specifically, you don't need to check in the XAP file that is generated in the ClientBin of your web app.
From MSDN (via this social.msdn thread):
You can add the following files to Visual Studio source control:
Solution files (*.sln).
Project files, for example, *.csproj, *.vbproj files.
Application configuration files, based on XML, used to control run-time behavior of a Visual Studio project.
Files that you cannot add to source control include the following:
Solution user option files (*.suo).
Project user option files, for example, *.csproj.user, *.vbproj.user files.
Web information files, for example, *.csproj.webinfo, *.vbproj.webinfo, that control the virtual root location of a Web project.
Build output files, for example, *.dll and *.exe files.
It doesn't say anything specific about Silverlight projects though.
Is Mercurial/TortoiseHG integrated into Visual Studio? i.e. can you check out/submit from within VS?
If so, if you right click on the project name and select "Add Solution to Source Control" it should add those parts of the project that it needs ignoring everything else.

Categories