I'm trying to create a Visual Studio 2013 custom project template that creates multiple projects. I'm having an issue because one of the projects has a glob include path to the other:
<Content Include="..\Project1\Content\**\*.*">
<Link>Content\%(RecursiveDir)%(FileName)%(Extension)</Link>
</Content>
The wizard to create the project seems to go through the path piece by piece (.., Project1, Content, **, .) and tries to create a file on disk. The problem is that '*' is an invalid file character.
Is there any way to accomplish this? Do I need to remove this from my template CSPROJ file and manually add it in the template wizard?
Related
I try to reference a collection of c# code to a console project in visual studio.
I want to keep the referenced code outside the console project folder.
I want the code to automatically update when it gets changed in the external position.
The referenced codes folder structure should stay intact. (~100 files)
Is there a way of referencing/linking the code without updating everytime? "Include in Project" only works if the code is inside a solution folder.
You can add a "link" to code files outside of your project. This doesn't make a copy of the files.
Right-click your project -> Add -> Existing Item..., and browse to the file(s). Then click the down-arrow on the "Add" button and select "Add As Link":
Linked files appear with a blue arrow in the Solution Explorer:
If you want to reference an entire folder structure of code, you'll need to edit your .csproj. Something like:
<ItemGroup>
<Compile Include="..\SomeDir\**\*.cs" Link="%(RecursiveDir)%(Filename)%(Extension)"/>
</ItemGroup>
Adjust ..\SomeDir to be the path to your code. The **\*.cs is of course a pattern to recursively include all .cs files. %(RecursiveDir), %(Filename), and %(Extension) are MSBuild placeholders.
I organise my git repos in a flat structure:
core
shared1
website1
website2
Where websites 1 and 2 both reference core and shared1.
When I add project references to core and shared1 from websites 1 and 2, they remain intact because they are both in the same relative location from the point of view of the websites.
Additionally, I organise my solution to mirror the external repo configuration, e.g.
core (solution folder)
corelibrary.csproj
shared1 (solution folder)
sharedlibrary.csproj
website1services.csproj
website1.csproj
I found a good solution, but I am curious if there is a better one. I am on Windows and using a simbolic link
cmd /c mklink /d /j _LinkedCode ..\..\..\_Code
then I can use "Include in Project" in visual studio
I'm using these tools and technologies:
Visual Studio 2019 CE
Windows 10
SQL Server
C# and ASP.NET MVC
Currently I create a new Visual Studio 2019 solution.
Add three/four nuget packages (automatically targets MVC).
Change a couple of files.
Setup configuration files.
Add standard/default project images.
I now start to develop the site as required.
I will check-in the project into Azure DevOps at the end of the day.
Is there a way to do the above 4 steps by the means of a template/package that I set once so in future I can click a few buttons in Visual Studio and all 4 steps have been done for me rather than having to do each step manually?
Errors
Error 1
This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props.
After attempting to Restore the packages
Error 2
An error occurred while trying to restore packages: Unable to find version 'XXXX' of package 'AAAA' C:\Program files(x86)\Microsoft SDKs\NuGetPackages: Package 'AAAA' is not found on source C:\Program files(x86)\Microsoft SDKs\NuGetPackages.... https://api.nuget.org/v3/index.json Package 'AAAA' is not found on source https://api.nuget.org/v3/index.json
There is something called a multi-project template. That same page has a specific section on creating a multi-project template from an existing solution:
Create a solution and add two or more projects.
Customize the projects until they are ready to be exported to a template.
On the Project menu, choose Export Template.
The Export Template Wizard opens.
On the Choose Template Type page, select Project Template. Select one of the projects that you want to export to a template, and then
choose Next. (You'll repeat these steps for each project in the
solution.)
On the Select Template Options page, enter a name and optional description, icon, and preview image for your template. Choose Finish.
The project is exported into a .zip file and placed in the specified output location.
Create a directory for your template, with a subdirectory for each project.
Extract the contents of each project's .zip file into the corresponding subdirectory that you created.
In the base directory, create an XML file with a .vstemplate file extension. This file contains the metadata for the multi-project
template. See the example that follows for the structure of the file.
Be sure to specify the relative path to each project's vstemplate
file.
Select all the files in the base directory, and from the right-click or context menu, choose Send to > Compressed (zipped)
folder. The files and folders are compressed into a .zip file.
Copy the .zip file into the user project template directory. By default, this directory is %USERPROFILE%\Documents\Visual Studio
\Templates\ProjectTemplates.
In Visual Studio, choose File > New > Project and verify that your template appears.
I'm using Visual Studio Community 2015 and need to view the designer.cs file for one of my webforms. However, when I expand the aspx file in the solution explorer, it does not show up. How do I force Visual Studio to show me the designer.cs file?
Here's what I see in Solution Explorer:
Also, I seem unable to edit the project file (.csproj) by hand so that it will show the designer.cs file because I can't find the project file in the folder containing the code. Here's a screenshot of that folder:
Folder Contents
In order for a designer file to show up beneath a source code file within the Project Explorer, the project file (.csproj) must have an entry as follows:
<Compile Include="page.aspx.cs">
<DependentUpon>page.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="page.aspx.designer.cs">
<DependentUpon>page.aspx</DependentUpon>
</Compile>
Please open your ProjectName.csproj file and check to see that this pattern exists for your source file (.cs) and designer source file (.designer.cs).
You will have to unload and then reload your project from Visual Studio for changes to the Project File to take effect.
Per Dave in the comments above - It appears that your project is configured as a web site instead of a web application. I would recommend that you convert your project to a web application by creating a new project and re-adding the files. You can read up on the differences between the two models here on MSDN
I am using Visual Studio 2013. I am trying to add a attribute in the .proj file to a .js file entry, so that the designer places the file beneath the corresonding file page file. For example, the designer will display Test.aspx, and beneath it will have test.aspx.cs and test.aspx.js.
Now, I have done this in an older Visual Studio such as 2010. I am wondering why it is not correctly working in Visual Studio 2013? An example o the entry is below:
<Content Include="Agent\Scripts\AgencySettings.aspx.js">
<DependentUpon>Agent\Profile\AgencySettings.aspx</DependentUpon>
</Content>
I do not see what I am doing incorrectly at the moment. Any help would be appreciated. Thanks!
I figured out the issue. For some reason if the file does not sit in the same directory, it cannot be nested to it. So, I had to move the .js file to be in the same directory as the .aspx file I wanted it to be nested with. That sucks, as I had done this before in prior visual studios, and was able to keep all script files in the scripts directory, but display them in the designer differently. Anyways, that change was the solution and here is the code entry for it:
<Content Include="Agent\Profile\AgencySettings.aspx.js">
<DependentUpon>AgencySettings.aspx</DependentUpon>
</Content>
The designer now shows the following files when looking at AgencySettings.aspx and expanding the file:
AgencSettings.aspx
-- agencySettings.aspx.cs
-- agencySettings.aspx.js
In my C# project have multi language support using resx files. People do translation using external software and then doing pull request those resx files.
So I'm wondering is there a way to add those resx language files to projects automatically?
Example pull request: https://github.com/ShareX/ShareX/pull/437 and have 58 resx files there for French and I need to add those to projects manually now.
You can manually edit the projects files to include all resx files using wildcards, ex.
<EmbeddedResource Include="**\*.resx" />
That way, you just need to add the files to the project's directory (or any subdirectory).
Note that you will need to unload/load the project in Visual Studio (if currently is opened) when adding new files before the new files get noticed by Visual Studio.
EDIT: Since you want the resx files to be grouped with the Forms - which is done in MsBuild via the DependentUpon parameter - you will need to do the following for each form:
<EmbeddedResource Include="MainForm*.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>