I have folders that fills by third part application, and I need to store all the files as part of my project. Include it one by one even manually a whole folder is pretty annoying, because I forced to make it everytime when new file apears or removes.
How to make it with Visual Studio Community?
I had similar issue working with webpack. I had to manually includes files in visual studio generated by webpack. You have to edit.csproj file.
Right click the project, and click on
Unload project
Right click the unloaded project and click on
Edit YOUR_PROJECT_NAME.csproj
Edit under , example, I wanted to include all files under my /Scripts/dist/ to be included whenever I was going to publish them. ** includes all files or folders.
You can also see other options here on VisualStudio documentation site.
<ItemGroup>
.... other items
<Content Include="Scripts\dist\**" />
.....other items
</ItemGroup>
You can also do it as,
<Content Include="css\*.min.css" />
<Content Include="js\*.min.js" />
If the files are dynamically created from outside (like webpack), then you can also set it to be invisible or hidden (greyed-out) by:
<Content Visible = "false" Include="Scripts\dist\**" />
Note: Even though you see files are greyed out (as if it was not included), the files will be included when you publish. In my case, it was included when I refreshed my project.
Related
I have a Visual Studio 2019 project. Was asked to make trial changes. Do not want to alter current project. Is there any way to copy a project so I do not have to start over from scratch?
Searched here and other forums and documentation and cannot find solution.
Short answer: you can very simply copy the directory in which your project reside on disk. Open the new directory and double click on the .csproj file and you are now working in your new copy of the project. But, if you want to do that in a more professional and maintainable way, please read on...
The best way to do that in a more robust way is using Git.
In the bottom right corner of Visual Studio find the "Add to Source Control" command, click it, then choose Git. Now the command says "master", that is your main "copy" of the project: in Git, this is called your main "branch".
Now click on it, choose "New branch", give it a name (e.g.: trial), leave the checkbox "Checkout branch" checked, then click on "Create branch". Now the command in the right bottom has changed to "trial".
Now you have another copy of your project: you can work on it, save your work on local disk. When you are ready to save it in Git, press the pencil icon, that is located in the bottom toolbar, on the right, near the command you used before (the number near it shows how many files you have changed): click it, enter a "commit message", then click on "Commit all". Now you have saved all your work in the trial "branch" of your project in Git.
If you want to come back to your initial copy of the project, click on "trial", then choose "master", and voila... your are now working on the old copy or your project. You can switch between the two branches anytime, only remember that, before switching, you have to "commit" your changes, that is, save them in Git, as I explained above.
At some point, you may want to bring the changes you made in trial to master. To do so, when you are working in master, click on master (always in the bottom toolbar, on the right), then choose "Manage branches", then right click on "trial", click on "Merge from...", then click the Merge button: you have now brought the changes made on trial into master. The only problem can arise if you have changed a file both in master and in trial, and the changes are conflicting: in this case, VS will warn you, show you the conflicting changes, and you will have to choose which version of the conflicting changes you want.
If one don't want or can't use git, one can also copy and paste the project folder. Once in the new folder, Here is what I usualy do (I assumed the old project is named "projectOld" and new one "projectNew").
:
rename projectOld.sln to projectNew.sln
open projectNew.sln and change the following line in order to set the new project name :
Project("{C9CE8BB8-8B4A-11D0-5E31-C9100A0BC942}") = "projectNew", "projectNew.vcxproj", "{66F6A241-22E1-4941-6DA3-B6D9E7A8AF86}"
rename projectOld.vcxproj to projectNew.vcxproj
open projectNew.vcxproj and change the lines with the <!-- here --> comments
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
[...]
<PropertyGroup Label="Globals">
[...]
<RootNamespace>projectNew</RootNamespace> <!-- here -->
[...]
<ProjectName>projectNew</ProjectName> <!-- here -->
[...]
<ItemGroup>
<ClCompile Include="..\..\..\..\..\IncludePath(1)\ImplementatFile(1).cpp" /> <!-- here -->
[... up to last]
<ClCompile Include="..\..\..\..\..\IncludePath(n)\ImplementatFile(n).cpp" />
[...]
<ItemGroup>
[same thing for every ItemGroups] <!-- here -->
[...]
rename projectOld.vcxproj.filters to projectNew.vcxproj.filters
rename projectOld.vcxproj.user to projectNew.vcxproj.user
one can delete the Debug and X64 folders, they will be created again by mvsc.
Yes, with GIT branching you can create variations of a project easily.
But I think that was not the core of the question asked, because if you create a branch, it is kept separate.
I had a similar scenario where I needed a similar project in the same solution (code first database). A clone of the database project to start with and make some changes for a different database. So in the end I wanted to have 2 databases, not identical but similar, in the same solution.
Adding a new project in the solution and then copying the .CS-Files is possible but cumbersome because of the references and dependencies.
So what I did is:
Close Visual Studio
Open the file explorer and copy the entire folder (e.g. MyProjectA), rename the copy (e.g. to MyProjectB)
Rename the .csproj project file of the copied project MyProjectB. Then open it with a text editor of your choice, to see if you need to adapt anything (for example, project references if you moved it to a different directory level; they usually refer to a different project with a relative path, e.g. <ProjectReference Include="..\SomePathOfADifferentProject\SomeProject.csproj"/>)
Open Visual Studio, load the solution
In the solution explorer, right click on the solution, select "Add existing project...". Now browse for MyProjectB to add it as existing project
and you're done!
If you're using source control like GIT, make sure to check if the clone was correctly added (i.e. check if the files are tracked by source control).
I suggest you go with Project Template inside Visual Studio. You create a project template, store it somewhere, then create a new project by using the stored template. Here are more details
https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/ms247121(v=vs.100)?redirectedfrom=MSDN
I have removed a View from my Views folder in a ASP.NET MVC project. When pushing it to VSTS DevOps, the Build fails because it can't find the removed file.
I see that in the .csproj file the following:
<Content Include="Views\SiteSettings.cshtml" />
Which is the file I have removed.
Why is this stil in here? In my Repo the file is completely removed from the Views folder.
How can this be automated that it also removed the entry in the .csproj file?
Or am I missing something here?
UPDATE
File was still in my soluion, right click Delete and pushing the csproj file to vsts solved the build error.
This usually happens when after removing a project file you don't explicitly Save the project in Visual Studio. In this case Git will only realize the file deletion, but not the project modification itself.
I think if one uses the Git support of Visual Studio then the chance gets smaller, but when using an external tool like Git commandline or GitExtensions for example, then there is a high chance for this issue.
Unfortunately I'm not aware of any workarounds or solutions except for always paying attention to it.
Open you project .csproj and remove this line, save, push and publish again.
<Content Include="Views\SiteSettings.cshtml" />
this will fix your problem about missing file.
Using VS 2017 with MVC 5 Razor views. When I publish my application, a handful of specific views do not get copied over.
I'd discovered several SE questions on this same issue from back in the 2010-2011 timeframe. At the time, the issue was that Build Action in the file's properties was not set to Content due to a bug in some early RC which has since been resolved. Well, all of mine already do day Content for Build Action.
Any reason why only a small number of views are not making it in the publish?
As far as I'm aware, there are only 2 things that can cause this to happen.
As you say in the question, the build action for each view needs to be set to "Content"
The view files need to be included in the project file, so in the .csproj file there should be a line like this:
<Content Include="Views\ControllerName\Index.cshtml" />
Another one would be to set this in your csproje file. This was missing in mine, which caused it to make a precompiledviews.dll in my publish:
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
Set it to false explicitely in order to publish .cshtml files.
Visual Studio -> Right click on "Views" in solution explorer. Click "Publish Views". This will set all the views to Content"
Depending on the version of Visual Studio, excluding and then including partial view or its folder may work or not. The most certain way to do it is to remove it from .csproj file and then include it again.
lets say _LoginPartial is not updated after publishing (especially if you have some razor code).
First open '.csproj' file, and remove
<Content Include="Views\Shared\_LoginPartial.cshtml" />
The build the project, and then add it again to .csproj, and rebuild and publish.
Another Solution From Visual Studio
right-click on the file and "Exclude From Project".
select the Project and click on "Show All Files" from Solution Explore (top horizontal menu bar on Solution Explore)
right-click on the file that Excluded and Click on "Include In Project".
This will automatically modify the .csproj file.
I am using Umbraco Forms and do not want that the forms included on the development environment are included on the production environment; however I would like them to be included in source control.
Therefore my current setup includes the files under source control as per standard; however to exclude the forms data (App_Plugins/UmbracoForms/Data) I excluded the folder from the project (.CSPROJ). The problem is that after publishing (to file), the data files are always being included anyway, even if they are excluded.
Is there something else going on in the build process that is copying these files to the publish directory?
This issue that App_Plugins get published is actually configured by the UmbracoCms package from NuGet. It allows you to publish the project including Umbraco. But it adds additional folders as well. When installing Umbraco on the project, it adds 2 Import to the .csproj file.
<Import Project="..\packages\UmbracoCms.{version_number}\build\UmbracoCms.props" Condition="Exists('..\packages\UmbracoCms.{version_number}\build\UmbracoCms.props')" />
<Import Project="..\packages\UmbracoCms.{version_number}\build\UmbracoCms.targets" Condition="Exists('..\packages\UmbracoCms.{version_number}\build\UmbracoCms.targets')" />
In this UmbracoCms.props file it refers to the property CopyAllFilesToSingleFolderForPackageDependsOn that is defined in MSBuild.
This task gets executed when the files are being packaged.
Within this property, it mentions the task AddUmbracoFilesToOutput.
This task is found in the UmbracoCms.targets.
Within this task, it defines a task named FilesForPackagingFromProject which is used in WebDeploy. In this task it uses all the Elements named CustomFilesToInclude. As you can see there is the following line:
<CustomFilesToInclude Include=".\App_Plugins\**\*">
<Dir>App_Plugins</Dir>
</CustomFilesToInclude>
It does not matter if you exclude the files, it will always be adding this because of the above line.
How to resolve this?
We cannot change this UmbracoCms.targets file so we have to take other options since we don't want to change the way Umbraco has specified these files.
What we can do is specifying excludes ourselves by doing this thesame way Umbraco did.
Add a new Target, an ItemGroup and add the element ExcludeFromPackageFolders, specify the Include attribute and fill this with the values.
<Target Name="ExcludeUmbracoFormsData">
<ItemGroup>
<ExcludeFromPackageFolders Include="App_Plugins\UmbracoForms\Data">
</ExcludeFromPackageFolders>
</ItemGroup>
</Target>
Then add a PropertyGroup with the Property CopyAllFilesTOSingleFolderForPackageDependsOn and specify the name of the target you just created.
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
ExcludeUmbracoFormsData;
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
Alternative
If you are using UmbracoForms 4.4+ you can define a different type of storage for your forms: https://our.umbraco.com/documentation/Add-ons/UmbracoForms/Developer/IFileSystem/
It sort of depends on how you are doing the publish. If you are just publishing through visual studio, you can add some parameters to the PropertyGroups of your csproj.
<ExcludeFoldersFromDeployment>App_Plugins\UmbracoForms\Data</ExcludeFoldersFromDeployment>
There is also some talk about doing this here: Web Deployment FAQ. If you do some googling about ExcludeFoldersFromDeployment you'll find some other ways to do this if you are calling MSBuild yourself.
/p:ExcludeFoldersFromDeployment="App_Plugins\UmbracoForms\Data"
When I select Add > New Item in my Xamarin.iOS project in VS 2012 or 2013, I see the screen below. Notably absent is "text file." Why might I be unable to add a text file?
There are a lot of other things missing in that list. The simplest solution would be to create that text file in the file system and then adding it to your project in Visual Studio. The easiest way to do this is to enable "Show All Files" at the top of the Solution Explorer, then right-click the text file and choose "Include In Project". After doing that, be sure to select the desired build action in the file's properties.
The other solution would be to add the entries by hand into the .csproj file. That would look something like this:
<Content Include="test.txt" />
<EmbeddedResource Include="test.txt" />
<BundleResource Include="test.txt" />
<None Include="test.txt" />
(pick one). You can do this in Visual Studio by right-clicking the project and selecting "Unload Project". After right-clicking the project again, the edit option appears.
What version of the tools are you using? I believe that was fixed in the newer releases