Is there a way to revision all projects in a solution? - c#

I have a solution with over 30 projects in it... Is there a quick and easy way of managing the build revision of all projects rather than editing the AssemblyInfo or Properties of each one?

In the past, I've followed the advice in this article to create a SharedAssemblyInfo.cs file at the solution level and linked to it from each of my projects.
The main point is that you want to add the SharedAssemblyInfo.cs file to your projects as a link. In Visual Studio, you would choose "Add Existing Item", but in the dialog, click the arrow on the Add button and select "Add As Link".
In SharedAssemblyInfo.cs, put any assembly attributes that you want to be the same across all projects. The article recommends the following:
AssemblyCompany
AssemblyProduct
AssemblyCopyright
AssemblyTrademark
AssemblyConfiguration
AssemblyDescription
CLSCompliant
ComVisible
AssemblyVersion
AssemblyInformationalVersion
Each project will still have its own AssemblyInfo.cs file as well to supplement the attribute it receives from the shared file:
AssemblyTitle
AssemblyCulture
Guid

I recommend using AssemblyInfo Task,
http://archive.msdn.microsoft.com/AssemblyInfoTaskvers
[Updated: it is an MSBuild targets from Microsoft MSBuild team. No Visual Studio addin is needed, so it works fine even if you use MSBuild directly.]
You can use its targets to modify a central AssemblyInfo.cs file and then link it to all projects. My open source project #SNMP shows how it is utilized,
https://github.com/lextm/sharpsnmplib

Normally this should be only a comment, but I want to give this as an answer
This addin for VS is a real lifesaver
Versioning Controlled Build
I'm so fond of this addin that I'm using it from the VS 2003 version.
Just pay attention and read all the article, there are some hiccups when other addins are installed
While the accepted answer is really good, I still prefer to have, for each project a separated assemblyinfo.cs, containing the FileVersion and AssemblyVersion attribute, because, in this way, I can increment these values separately, when there is a bug fix or a revision to distribute

Related

Writing a library in a framework [duplicate]

I'm writing a class library for a simple parser in C#. When I first created it, I used .NET standard 2.0, but now I need to migrate it to .NET 4.6 both to conform to the other projects in my solution and in order to use NUnit.
I tried to follow the instructions in the Microsoft documentation, but when I try to select another framework in the properties, I can only find other .NET standard versions.
How can I migrate it? Will I need to manually edit the .csproj file?
Open up the project file (.csproj) and change the TargetFramework to net462
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
</PropertyGroup>
My personal experience in Visual Studio 2017 is that recreating project and adding existent sources is the simplest, safest and most effective way - because .Net Framework based csproj file has extra xml elements (comparing with Standard based), it seems changing "TargetFramework" is not enough.
Below is portion of diffs appeared by default:
If you are publishing your class library as a Nuget package then there is a better way to set this up. Check out this article:
https://weblog.west-wind.com/posts/2017/Jun/22/MultiTargeting-and-Porting-a-NET-Library-to-NET-Core-20
Basically you can setup your class library for multi targeting, allowing it to be imported into .net core projects as well as different versions of .net frameworks.
There are a few steps that I did and worked for me:
git push your code, so you have a back up :)
Unload the project in VS (right click on the project and unload)
Edit the project in VS (right click and edit)
Replace the TargetFramework OR/AND TargetFrameworkVersion with
<TargetFramework>netcoreapp2.0</TargetFramework>
Change the project line, that's usually the first line (after xml root) to:
<Project Sdk="Microsoft.NET.Sdk">
Remove the import that's usually the second line (after the xml root)
Keep your PropertyGroups that describe the build options, if you want (I want mine as are custom)
Remove the references and the file references, they are not needed.
Close the file and reload (right click reload).
Delete the assemblyinfo file (from properties folder) as it is not needed, the assembly version comes now from the proj
Right click on the project and go to properties to see that you don't have any error in proj file. Ensure that you don't have typos or tags that are not close.
Build. If you have dependencies that you are missing then right click and on the project and add them. - I suppose that you don't want to edit them in the proj. Or you can do a dotnet restore or dotnetbulid to add them, as you would like.
Hope this works for you. They seem a lot of steps but they are not that complicated, and this is one time effort.

Simple approach to updating AssemblyInformationalVersion via TeamCity's AssemblyInfo patcher feature

By default a Visual Studio C# Library/Console etc project comes with an AssemblyInfo.cs file that does not include AssemblyInformationalVersionAttribute. TeamCity allows patching this attribute if found in AssemblyInfo.cs using AssemblyInfoPatcher.
Problem
A zero effort way of including AssemblyInformationalVersion for TeamCity.
Possible Solutions
Use a GlobalAssemblyInfo.cs file and link to each project, downside: each new project will have to be linked, frustratingly annoying if (often) forget to create link
Add AssemblyInformationalVersionAttribute to all templates in Common7\IDE\ProjectTemplates\CSharp\, downside: do it on each devs machine, mainly overkill
A first build step that runs a script based on this SO answer and creates links on all .cspprojs, downside: will have to check back in for patching step, overly complicated
Reason
The AssemblyInformationalVersion is useful because you can put any text there - I like to put the git hash of the commit used to build the assembly in it
Have you a better idea?

External msproject, imported in CMake, would not build

I have a CMake-based C++ project, and recently I've included existing C# program into it.
Here is CMake code:
include_external_msproject(MarkTrainingSet MarkTrainingSet.csproj
GUID 77A5B8C9-998E-4D0E-A444-6AD14FB0DC37
PLATFORM AnyCPU)
The .csproj file was generated by the same Visual Studio 2013, as builds my C++ project. GUID value and AnyCPU platform are the values from that file.
My problem is that this C# project is not built when I issue Build solution command to the Visual Studio.
I have to go to the solution properties (right-click on the solution in Solution Explorer), then Configuration Properties -> Configuration, and manually check Build checkbox in the line, corresponding to my MarkTrainingSet project.
If CMake regenerates the solution, I have to recall about that checkbox and redo the procedure.
The documentation about include_external_msproject is very incomplete.
What should I do to make this C# project always build automatically?
The last time I looked, CMake's implememtation of include_external_msproject() is restricted to C/C++ projects.
You may find this defect report worth a look, though it looks stale. http://www.cmake.org/Bug/view.php?id=9742 ... ( also see http://marc.info/?l=cmake&m=133319401303885 )
I couldn't get a sense of whether the patches were included in CMake or not though, but the defect is still open.
Generally syntax looks like this:
include_external_msproject(projectname folder/projectname.csproj PLATFORM AnyCPU)
Seems to work with vs2019 included cmake.

Add referenced projects into solution automatically

My situation:
I have a solution A with hundreds of projects,
Some of projects are class libraries and are referenced from other projects.
Now I want to create a new solution B which will consist of subset of projects of solution A. I start by adding the first pre-existing project into this new solution B. This project is referencing couple of class libraries from solution A. Therefore it is logical that these libraries cannot be found and I cannot build. Of course I could add all the referenced projects manually into the new solution B but that would take quite a long time, considering the total amount of projects that I need to add.
Is there some built in Visual Studio feature that can take care of this on my behalf? I.e. I will be offered an opportunity to import all the referenced projects at once and the B.sln file will be updated automatically.
I also have a ReSharper extension but I couldn't find such feature in there as well.
EDIT:
Some more detail on what I am trying to achieve. A.sln has lots of application projects and literally hundreds of class libraries. I want to create a new B.sln for one particular application project from A.sln and only add the class libraries that it is referencing, directly or indirectly... But the dependencies can go up to 15 levels deep so manually removing projects from original A.sln to create B.sln is really not suitable for me as I would have to carefully consider each one of the projects that I would be manually removing from the original sln file, subsequently reviewing the csproj files to find whether the application I am interested in does not indirectly depends on them via one of its direct references.
Copy paste your current solution file and start with it. Open it in new Visual Studio Instance. Remove your projects one by one. Instead of adding new projects, removing unnecessary ones will be more easy for you. As far as I know there is no such feature in Visual Studio as you want.
Removing will be more easy since projects are already there. Do not use Visual Studio to remove project but open sln file in suitable programmers notepad. Your projects are added to sln file as below lines.
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Integration.App1", "..\Example.Integration\Example.Integration.App1\Example.Integration.App1.csproj", "{E3977144-AFBA-451D-894C-1F89AA008041}"
EndProject
Removing such lines will be more easy if your projects has naming convention.
The best way to port references from an existing project that I've found is to generate a template for that project.
On the File menu, click Export Template. The Export Template wizard opens.
Choose project template and move through the wizard
Click Finish. Your project is exported into a .zip file and placed in the specified output location, and, if selected, imported into Visual Studio.
Now, when you setup a new project for solution B. You'll be able to choose the project template from A and all the file structure/references are preserved.
Ref: http://msdn.microsoft.com/en-us/library/vstudio/xkh1wxd8%28v=vs.100%29.aspx

What causes AssemblyInformationVersion to appear in some but not all AssemblyInfo.cs files?

i have just started at a new company where i am basically looking after solution builds using TFS 2010. i have added a few new custom activities to increase version numbers in the AssemblyInfo files of the projects and this is working fine. The problem im finding is that all AssemblyInfo.cs files have the AssemblyVersion and AssemblyFileVersion numbers, but only some have an AssemblyInformationVersion number aswell. Can anyone please tell me what causes the AssemblyInformationVersion to appear in some AssemblyInfo.cs files and not others?
Thanks
[AssemblyInformationalVersion] is an optional attribute that maps to the ProductVersion property of the application. If it is not present, the value specified in the [AssemblyVersion] attribute is used instead.
As far as I can tell, Visual Studio never adds [AssemblyInformationalVersion] attributes to the AssemblyInfo.cs files it generates. The developers might have added those if they wanted the product version to be different from the assembly version in some of your projects.

Categories

Resources