We have a build server that is managing version numbers. When we debug we create a local build that also tries to manage the version numbers. The result is perpetual version control (SVN) conflicts in AssemblyInfo.cs that need to be resolved.
Note: we are using [assembly: AssemblyVersion("w.x.y.z")], and not the wildcard mentioned by #estebane below.
How does one turn off the auto increment feature of Visual Studio 2010?
Try this:
open project properties in VS
click the Application tab
click "Assembly Information" button
set both Assembly and File version
clean solution and rebuild
clean and rebuild projects that use your dll as reference
If this doesn't work your problem is elsewhere.
You can check the effect on these settings by finding the dll in windows explorer, right-click, select "Properties", click on "Details" tab and check the File version and Product version fields. If these behave as expected try tracking down where is your out-of-date copy that you're actually loading.
In your AssemblyInfo file you can set the version and avoid auto increment using
[assembly: AssemblyVersion("1.0.0.0")]
If auto increment is active it looks like
[assembly: AssemblyVersion("1.0.*")]
Try with the following to set a fixed Assembly version of 1.0.0.0 and a fixed File Version of 1.0.*.
[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("1.0.*")]
Hope this will stop incrementing your assembly version.
Do you have any pre or post build steps that are changing it? Maybe look in the build's output window to see if that gives any indication of what process might be changing it.
If you originally have [assembly: AssemblyVersion("1.0.0.0")] in your AssemblyInfo.cs file and it changes post build, something other than VS.NET is modifying that file.
Seems like you have another non-default software/plugin/extension updating your version number. Because Visual Studio won't do it when you don't use wildcards.
Check your Visual Studio AddIns list and Extensions list.
Related
As the title suggests I need to assign an application a custom file and/or product version by building a project from Visual Studio.
I know you can assign a build number from an application publish but I am not publishing these applications, I am simply building "release" files.
Is there a way within Visual Studio to specify these file versions before I build the application?
Thanks in advance!
Is there a way within Visual Studio to specify these file versions before I build the application?
Yes, you can specify File/Product version by AssemblyInfo.cs before you build the application.
First, the File version looks for the attribute AssemblyFileVersion in the AssemblyInfo.cs file. So you can specify the File version by setting the value AssemblyFileVersion. I change the AssemblyFileVersion value from 1.0.0.0 to 2.0.0.0:
[assembly: AssemblyFileVersion("2.0.0.0")]
Second, ProductVersion first looks to see if the assembly containing the main
executable has the AssemblyInformationalVersion attribute on it. If this
attribute exists, it is used for Product Version.
If this attribute does not exist, both properties use the AssemblyFileVersion instead.
So, in your project, open the AssemblyInfo.cs file. In this file, I added a
line like this:
[assembly: AssemblyInformationalVersion("4.0.0.0")]
Then after build is complete. The file version is 2.0.0.0 and the product version is 4.0.0.0.
Is there a tool to update the assembly version in AssemblyInfo.cs for all projects in a solution?
I have a solution which has about 30+ projects and I don't see myself checking out AssemblyInfo.cs for each of these projects from source control(TFS) and doing this manually.
Basically I'm looking for something that will remove
[assembly: AssemblyFileVersion("1.0.0.0")] and change
[assembly: AssemblyVersion("1.0.0.0")] to [assembly: AssemblyVersion("1.0.*")]
I could set the source control plugin settings to automatically check out instead of prompting but still need to have AssemblyInfo update automatically somehow.
I always do that during the Build. See http://www.ewaldhofman.nl/post/2010/05/13/Customize-Team-Build-2010-e28093-Part-5-Increase-AssemblyVersion.aspx for detailed steps
I just wondered if it possible within various Visual Studio versions to automatically remove all references from a project that were never been used?
In your answer, please specify which version of VS the solution applies to.
If you have Resharper (plugin) installed, you can access a feature that allows you to analyze used references via Solution Explorer > (right click) References > Optimize References...
http://www.jetbrains.com/resharper/webhelp/Refactorings__Remove_Unused_References.html
This feature does not correctly handle:
Dependency injected assemblies
Dynamically loaded assemblies (Assembly.LoadFile)
Native code assemblies loaded through interop
ActiveX controls (COM interop)
Other creative ways of loading assemblies
All you need is stone and bare knuckle then you can do it like a caveman.
Remove unused namespaces (for each class)
Run Debug build
Copy your executable and remaining namespace references to new location
Run the executable
Missing Reference DLL error will occur
Copy required DLL from Debug folder
Repeat 4-6
Gu Gu Ga Ga?
Throw your stone
You can also rely on your build tools to let you know which reference is still required. It's the era of VS 2017, caveman still survived.
The Resharper extension will do this for you.
This extension supports Visual Studio 2005 through 2017.
While the compiler won't include unused assemblies, extraneous using statements and references slows down Visual Studio and Intellisense, since there's more code the tools have to consider.
You can try the free VS2010 extension: Reference Assistant by Lardite group. It works perfectly for me. This tool helps to find unused references and allows you to choose which references should be removed.
In a Visual Basic project there is support to remove "Unused References" (Project-->References-->Unused References). In C# there isn´t such a function.
The only way to do it in a C# project (without other tools) is to remove possible unused assemblies, compile the project and verify if any errors occur during compilation. If none errors occur you have removed a unused assembly. (See my post)
If you want to know which project (assembly) depends on other assemblies you can use NDepend.
With Visual Studio versions 2017 and 2015, you can do this with the Code Map feature, but this feature is only available in the Enterprise Edition, not the Community or Professional versions.
Right-click on the project node in the solution explorer and select 'Show on Code Map.' This will display your .dll as a single node in a blank graph. Right-click on that node in the Code Map and select "Show Assemblies This References." This will add an additional node called "Externals" which can be expanded to show only the assemblies that are actually referenced.
For Visual Studio 2013/2015/2017 there is an extension that does exactly what you want: ResolveUR. What this basically does is:
reference is removed in the project
project is compiled with msbuild
check for build errors
restore removed references if there were build errors.
For anybody coming here looking for Visual studio 2012:
Download and Install Reference Assistant for Visual Studio 11
Later you can do:
In Visual Studio 2013 this extension works:
ResolveUR
Some people suggested to use an awesome tool - Reference Assistant for Visual Studio. The problem is that VS2012 is the latest supported Visual Studio. But there is the way to make it work in VS2013 as well ;)
And here is how:
1) Download Lardite.RefAssistant.11.0.vsix
2) Change the extension to zip: Lardite.RefAssistant.11.0.vsix -> Lardite.RefAssistant.11.0.zip
3) Unzip and open the extension.vsixmanifest file in the text editor
4) Find all occurences of InstallationTarget Version="[11.0,12.0)" and replace them with InstallationTarget Version="[11.0,12.0]" (note the closing bracket)
5) Save the file and zip all files so they are on the root zip level
6) Change the extension of the new zip to vsix
7) Install and enjoy :)
I've tested it with VS2013, thanks source for the tutorial
EDIT
Add to support VS 2015 Community Edition
<InstallationTarget Version="[14.0,15.0]" Id="Microsoft.VisualStudio.Community" />
Meaning of the brackets
[ – minimum version inclusive.
] – maximum version inclusive.
( – minimum version exclusive.
) – maximum version exclusive.
[Update] This feature is only available for .Net core projects.
This feature will be coming to Visual Studio 2019 very soon and already available with Visual Studio 2019 v16.10 Preview 1.
This option is turned off by default, but you can enable it under menu Tools > Options > Text Editor > C# > Advanced. Select the Remove Unused References command in Solution Explorer (Experimental). Once the option is enabled, the Remove Unused References command will appear in the right-click menu of a project name or dependencies node.
You can use Reference Assistant extension from the Visual Studio extension gallery.
Used and works for Visual Studio 2010.
In the VS2022 (preview at the moment of writing) this comes out of the box for SDK Style Projects (read: .NET Core and newer).
If it is available you can find it in the project context menu:
You get to choose what to do with each finding.
Read more about it here.
Pro-tip: Check if your project compiles and runs correctly after applying this. In my experience it doesn't check whether a dependency is used at runtime, for instance.
Using DevExpress, I follow these instructions:
In VS, go to DevExpress - Editor - Code Cleanup. Under Rules, check 'Remove unused namespace references'. Click OK.
Right-click on the solution, and choose 'Code Cleanup'. The cleanup runs for a few minutes, and finishes.
Build your application
The following method does not depend on any 'add-on's and is not very painful.
Step through each of your source files and
Select all (Ctrl-A)
Toggle outline expansion (Ctrl-M, M). This will reduce the file to two lines.
Click on the namespace's '+'. This will show each of the file's classes as a single line. Scan each class's reference count, looking for unreferenced classes.
Click on each of the classes' '+'. This will show each of the class functions as a single line. Scan each function's reference count, looking for unreferenced functions.
Scanning each file looking for '0 reference' takes only a second.
Scanning an entire project takes only a couple of minutes.
In VB2008, it works this way:
Project>Add References
Then click on the Recent tab where you can see list of references used recently. Locate the one you do not want and delet it. Then you close without adding anything.
How to setting-up visual studio 2010 to set as auto-increment version of project on each build?
Does this feature exist on vs2010?
Change the AssemblyInfo.cs-File:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
to
[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
As someone else mentions the 1.0.* is always replaced with 1.0.{date}.{time] so it should be always be increment (you would have thought)
In VS2010 changing the AssemblyVersion to [assembly: AssemblyVersion("1.0.*")] works, be warned that you must close the solution/project, re-open it then re-build it (not build) to refresh/change the build+revision values.
The date/time appears to be obtained from the time the project is opened thus the close/re-open to refresh the revision/build values, I guess this is useful if you are changing various bits within the project in one go and it won't keep changing the AssemblyVersion possibly breaking other bits.
To return the date from the build value:
DateAdd(DateInterval.Day, build, DateValue("01/01/2000"))
' build is the number of days from 1/1/2000
To return the time from the revision value:
Date.FromOADate(revision / 1800 / 24)
' depending on your timezone you may have DST/BST issue with resulting time
The AssemblyInfo.cs - file doesnt exist if you're deveolping native software with c/c++ ... hence this answer is useless for a whole lot of developers out there - one could have a look into http://autobuildversion.codeplex.com ... but this extension doesnt seem to work with VS2010 although the website says otherwise - you may be good to go if you're using older versions of VS, though
I just tried the autobuildincrement method and had problems with Visual Studio 2010 however I found a way to make it work. Set "Increment Before Build to false. Then even in Visual Studio 2010 the assempblyinfo.cs file will be updated after each build.
Note the assembly info on your dll won't change on your first build, but it will after that.
DateTime.Parse(#"1/1/2000")
.AddDays(FileVersionInfo.GetVersionInfo(
System.Reflection.Assembly.GetEntryAssembly().Location
).FileBuildPart)
.AddSeconds(FileVersionInfo.GetVersionInfo(
System.Reflection.Assembly.GetEntryAssembly().Location
).FilePrivatePart * 2)
I am currently working on a server control for other applications in our company to interface with a WCF service. Every time I make a change code change and recompile the control, I increment the the AssemblyVerison and AssemblyFileVersion class in the AsseemblyInfo.cs by one. For example, my latest build went from 1.0.07.0 to 1.0.08.0.
When the consuming application updates the file by copying the latest file in the bin directory and tries to compile, they receive the following error:
The type or namespace name 'MyControl'
does not exist in the namespace
'MyNamespace' (are you missing an
assembly reference?)
In order to resolve this error, they have to delete the current reference and re-add the reference.
Is there any way to update the server control without having to delete and re-add the reference?
I am not strong naming the server control.
#JPunyon - Do you mean have the consuming application add the server control project to their solution?
In my case it was a project defined using Target Framework: ".NET Framework 4.0 Client Profile " that tried to reference dll projects defined using Target Framework: ".NET Framework 4.0".
Once I changed the project settings to use Target Framework: ".NET Framework 4.0" everything was built nicely.
Right Click the project->Properties->Application->Target Framework
Right-click the assembly reference in the solution explorer, properties, disable the "Specific Version" option.
If none of the solutions above worked, try this 10-second fix.
Navigate to the startup project in solution explorer. Right click, properties > Application > Target framework. Change the target framework to anything else. Press Yes for the confirmation dialog. Give the changes a few seconds to take effect, then switch the framework back to what it was before.
The error will hopefully go away for you like it did for me!
Are you strong-naming your assemblies? In that case it is not a good idea to auto-increment your build number because with every new build number you will also have to update all your references.
I bumped the answer that pointed me in the right direction, but...
For those who are using Visual C++:
If you need to turn off auto-increment of the version, you can change this value in the "AssemblyInfo.cpp" file (all CLR projects have one). Give it a real version number without the asterisk and it will work the way you want it to.
Just don't forget to implement your own version-control on your assembly!
If the code is working previously and is throwing errors now, as mentioned in the above answers one of the config could have been modified. In brute force approach, close the VS editor and delete .vs folder in the same directory of the .sln file. All the config will be cleared and picked up from the repo files.
In my case, I had to change the Copy Local setting to true (right-click assembly in solution explorer, select properties, locate and change value of Copy Local property). Once this setting was changed, publication of my WCF service copied the file to the server and the error went away.
I encountered this error with an Azure DevOps Services (MS-hosted) build pipeline on a TFVC repo.
In my case, I was working within a branch and had accidentally added the reference from the package folder in trunk instead of from the branch. Once I added the reference from within the branch, it started compiling successfully.
I.e., while working on \branch-beta\sierra.csproj, I accidentally referenced \trunk\packages\delta.dll. Obviously, I needed to reference \branch-beta\packages\delta.dll instead. The mixup occurred because the path is not prominently displayed in the Add Reference window and I didn’t check carefully enough.
I found this issue in Visual Studio 2019 Version 16.4.4
I resolved most issues by discovering that the
packages.config
was missing the appropriate reference
eg:
<package id="System.Runtime" version="4.3.0" targetFramework="net461" />
Delete 'Web.Debug.config' and 'Web.Release.config' file for your solution directory,it should remove all errors
While creating new Blank UWP project in Visual Studio 2017 Community, this error came up:
After restoring the NuGet cache the reference resurfaced in the Project.