how to auto increment project version number on VS 2012 - c#-4.0

I searched for auto incrementing version number and found some solutions but I wonder which one is the most efficient and recent way? I do not know if there is a new feature or tool on Visual Studio 2012.
1st:
changing AssemblyInfo.cs file
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
2nd:
codeplex (I don't know if it is compatible on VS2012)
3rd:
Project properties under Publish
4th:
Using T4 templates to manage assembly version information
Please suggest any other solutions or share your experience about versioning?

Download and install AssemblyInfoTask
You need to get this custom build task. Chris references the original source at gotdotnet.com which does not exist anymore. Either search for the text AssemblyInfoTaskvers with google or try this link
http://code.msdn.microsoft.com/AssemblyInfoTaskvers/Release/ProjectReleases.aspx?ReleaseId=232
It should redirect you to the download area on MSDN where you can get the lates setup release.
Import the task into your build project
Open Source Control in Visual Studio and make sure you have a local copy of the build project in your workspace. Then check out the TFSBuild.proj file (Unchanged, keep any existing lock) and open it. Add the following line right after the import of Microsoft.TeamFoundation.Build.targets:
<Import Project="$(MSBuildExtensionsPath)¥Microsoft¥AssemblyInfoTask¥Microsoft.VersionNumber.Targets"/>
Use a custom task for retrieving the revision number
Each buildnumber contains a revision: FooBar_20090128.3 What we want to do is using this revision number also as revision in our Assembly version. So we need to implement a custom build task that is able to extract the revision number from the buildnumber so that we can assign it to the Assemblys' revision number. At the end of this article, I will post the sources you will need.
Right after the import statement from above, register this custom build task by adding the following line:
<UsingTask TaskName="ExtractRevision.ExtractRevisionTask" AssemblyFile="ExtractRevision.dll"/>
To configure all assembly properties and format the number formats respectively, add the following lines to your project file:
<PropertyGroup>
<!– Assembly version properties. Add others here –>
<AssemblyMajorVersion>4</AssemblyMajorVersion>
<AssemblyMinorVersion>0</AssemblyMinorVersion>
<AssemblyBuildNumber>0</AssemblyBuildNumber>
<AssemblyRevision>0</AssemblyRevision>
<AssemblyFileMajorVersion>4</AssemblyFileMajorVersion>
<AssemblyFileMinorVersion>0</AssemblyFileMinorVersion>
<AssemblyFileBuildNumber>0</AssemblyFileBuildNumber>
<AssemblyFileRevision>0</AssemblyFileRevision>
<AssemblyBuildNumberType>DateString</AssemblyBuildNumberType>
<AssemblyBuildNumberFormat>MMdd</AssemblyBuildNumberFormat>
<AssemblyRevisionType>NoIncrement</AssemblyRevisionType>
<AssemblyRevisionFormat>0</AssemblyRevisionFormat>
<AssemblyFileBuildNumberType>DateString</AssemblyFileBuildNumberType>
<AssemblyFileBuildNumberFormat>MMdd</AssemblyFileBuildNumberFormat>
<AssemblyFileRevisionType>NoIncrement</AssemblyFileRevisionType>
<AssemblyFileRevisionFormat>0</AssemblyFileRevisionFormat>
<!– Dump the TFS BuildNumber to the Assembly Comment Prop –>
<AssemblyDescription>$(BuildNumber)</AssemblyDescription>
<!– TF.exe –>
<TF>"$(TeamBuildRefPath)¥..¥tf.exe"</TF>
<!– AssemblyInfo file –>
<AssemblyInfoSpec>AssemblyInfo.*</AssemblyInfoSpec>
</PropertyGroup>
Set the revision number
By altering the target CheckSettingsForEndToEndIteration, you can use the custom build task you have yet to implement for extracting the revision number from the buildnumber and add it to the assembly version:
<!–for 2008 use the GetBuildProperties Task to get the BuildNumber –>
<GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)">
<Output TaskParameter="BuildNumber" PropertyName="BuildNumber"></Output>
</GetBuildProperties>
<!– extract the BuildRevision –>
<ExtractRevisionTask BuildNumber="$(BuildNumber)">
<Output TaskParameter="BuildRevision" PropertyName="BuildRevision" />
</ExtractRevisionTask>
<!– update the AssemblyInfo Props –>
<CreateProperty Value="$(BuildRevision)">
<Output TaskParameter="Value" PropertyName="AssemblyRevision"/>
</CreateProperty>
<CreateProperty Value="$(BuildRevision)">
<Output TaskParameter="Value" PropertyName="AssemblyFileRevision"/>
</CreateProperty>
<!– just needed if you populate the AssemblyDescription too like in the sample –>
<CreateProperty Value="$(BuildNumber)">
<Output TaskParameter="Value" PropertyName="AssemblyDescription"/>
</CreateProperty>
Check out and back in all AssemblyInfo.[cs|vb] files from your workspaces
Before you can alter the AssemblyInfo files, you need to let Team Build check them out:
<!– Set the AssemblyInfoFiles items dynamically –>
<CreateItem Include="$(SolutionRoot)¥**¥$(AssemblyInfoSpec)">
<Output ItemName="AssemblyInfoFiles" TaskParameter="Include" />
</CreateItem>
<Message Text="These AssemblyInfo.* files were found:"/>
<Message Text ="#(AssemblyInfoFiles)"/>
<Exec WorkingDirectory="$(SolutionRoot)"
Command="$(TF) checkout "#(AssemblyInfoFiles, '" "')""/>
Right after the altered files have been compiled, you can check them back in:
Command="$(TF) checkin /comment:"Auto-Build: Version Update" /noprompt /override:"Auto-Build: Version Update" "#(AssemblyInfoFiles, '" "')""/>
Just in case anything bad happens, there is a way of undoing the changes:
<!– In case of Build failure, the AfterCompile target is not executed. Undo the changes –>
<Target Name="BeforeOnBuildBreak" Condition="'$(IsDesktopBuild)'!='true'">
<Exec WorkingDirectory="$(SolutionRoot)"
Command="$(TF) undo /noprompt "#(AssemblyInfoFiles, '" "')""/>
</Target>
Implement the ExtractRevision custom build task
Simply create a new C# library project with the following class (and add a strong name to it by signing it in the project properties):
namespace ExtractRevision
{
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
public class ExtractRevisionTask : Task
{
public override bool Execute()
{
int indexOfDot = buildNumber.LastIndexOf(".");
if (indexOfDot != -1 & indexOfDot != buildNumber.Length – 1)
{
buildRevision = buildNumber.Substring(indexOfDot + 1, buildNumber.Length – (indexOfDot + 1));
}
else
{
//there is no char following the dot or we can't find a dot
buildRevision = "0″;
}
return true;
}
private string buildRevision;
private string buildNumber;
public string BuildNumber
{
set { buildNumber = value; }
}
[Output]
public string BuildRevision
{
get { return buildRevision; }
}
}
}
You need to check in the .dll file directly into your TeamBuildTypes folder on TFS.
External Link : http://devsid.blogspot.in/2010/06/automatically-increment-assemblys.html

Related

ReSharper - Document Saved Event For Inactive File in Visual Studio

I’ve set up my own source control plug-in for Visual Studio.
It’s registered with visual studio and can be selected from the list of Source Control plug-ins.
I’ve got no issues with files that are modified from with in Visual Studio as I’m using to catch the event before save:
IVsRunningDocTableEvents3
If the file isn’t loaded as an active document in Visual Studio, I’m having problems detecting that it is about to be edited so I can check it out of Source Control.
I’ve tried using the ReSharper event – DocumentManagerOperations suggested here:
https://resharper-support.jetbrains.com/hc/en-us/community/posts/205991489-Document-Saved-Event
I’m having issues detecting if these types of files need checked out:
.DotSettings. – When saving the ReSharper options settings
csproj – When adding Nuget Packages with ReSharper.
.cs when editing files that are not opened in VS with ReSharper, i.e.
fix naming in project.
Is there an event that’s triggered when a file is edited but not loaded?
Thank you!
I used the interface:
IVsQueryEditQuerySave2
More information here:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.interop.ivsqueryeditquerysave2?view=visualstudiosdk-2017
And made use of:
public int QueryEditFiles(uint rgfQueryEdit, int cFiles, string[] rgpszMkDocuments, uint[] rgrgf,
VSQEQS_FILE_ATTRIBUTE_DATA[] rgFileInfo, out uint pfEditVerdict, out uint prgfMoreInfo)
And:
public int QuerySaveFiles(uint rgfQuerySave, int cFiles, string[] rgpszMkDocuments, uint[] rgrgf,
VSQEQS_FILE_ATTRIBUTE_DATA[] rgFileInfo, out uint pdwQsResult)
something like this:
if (rgfQueryEdit != (uint)tagVSQueryEditFlags.QEF_ReportOnly)
{
if (rgpszMkDocuments != null)
{
foreach (var doc in rgpszMkDocuments)
{
//Do Something
Hope that helps you out.

kofax export script project setup

For my first export script I took the KCEC example and the APIRefExport.chm documentation to create my project by replacing the example code with my own.
I would like to create a clean export script from scratch.
I created a new class library project and called it EmptyExportScript (placeholder). The target framework is .Net 4. The platform target is x86 and the output path is .....\Program Files (x86)\Kofax\CaptureSS\ServLib\Bin\. When debugging I would like to start the administration module so I set this path .......\Program Files (x86)\Kofax\CaptureSS\ServLib\Bin\.
The option "Make assembly COM-Visible" is checked and I added the Kofax.ReleaseLib.Interop.dll to the references.
For the KfxReleaseScript.cs I added this code
[ClassInterface(ClassInterfaceType.None)]
[ProgId("KFXTS.EmptyExportScript.KfxReleaseScript")]
public class KfxReleaseScript
{
public ReleaseData documentData;
// public KfxReturnValue OpenScript()
// public KfxReturnValue ReleaseDoc()
// public KfxReturnValue CloseScript()
}
For the KfxReleaseScriptSetup.cs I added this code
[ClassInterface(ClassInterfaceType.None)]
[ProgId("KFXTS.EmptyExportScript.KfxReleaseScriptSetup")]
public class KfxReleaseScriptSetup
{
public ReleaseSetupData setupData;
// public KfxReturnValue OpenScript()
// public KfxReturnValue CloseScript()
// public KfxReturnValue RunUI()
// public KfxReturnValue ActionEvent(KfxActionValue actionID, string data1, string data2)
}
Lastly I added a Form to the project when running the UI.
For registration I added a EmptyExportScript.inf with this content
[Scripts]
Empty Export
[Empty Export]
SetupModule=EmptyExportScript.dll
SetupProgID=KFXTS.EmptyExportScript.KfxReleaseScriptSetup
SetupVersion=10.2
ReleaseModule=EmptyExportScript.dll
ReleaseProgID=KFXTS.EmptyExportScript.KfxReleaseScript
ReleaseVersion=10.2
SupportsNonImageFiles=True
SupportsKofaxPDF=True
RemainLoaded=True
SupportsOriginalFileName=False
When building the project .dll and .inf file get placed into the kofax bin directory.
I recognized that other scripts have a .pdb and .dll.config file in there too.
How do I get them?
When trying to install the custom script, I can add it to the script installation manager but I can't install it. There is nothing to install so I think I'm missing the .pdb and .dll.config file.
Is anything else missing?
Thanks for help :)
Kofax does not need a pdb file, but they are handy if you want to debug your connector and attach it to the release.exe process (learn more about them here).
I would not recommend changing the output path itself to Capture\Bin, but rather create a post-build event:
For example, the following line copies all required files to a separate folder under the CaptureSS\Bin folder:
xcopy "$(TargetDir)*" "C:\Program Files (x86)\Kofax\CaptureSS\ServLib\Bin\SmartCAP\kec\SmartCAP.KEC.Template\" /Y /S
Having a dll.config file is possible, but rare. I would rather recommend storing process-specific data in a custom storage string object of the respective batch class definition (which has the added benefit that you can just import/export the definition along with the batch class, and that you can display and have it changed it in setup form). Having said all that, back to your initial issue - the connector can't be installed.
COM visibility
The assembly needs to be COM-visible, but you mentioned that it was. For the sake of completeness, here's what you will need to do. Note that the GUID must be unique (only relevant if you copied an existing solution):
If you're installing the connector on a different machine, you will need to register it first using regasm.exe - here's an example:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" SampleExport.dll /codebase /tlb:SampleExport.tlb
ProgIds
Then, your .inf file needs to contain the precise ProgIDs:
[Scripts]
SampleExport
[SampleExport]
SetupModule=SampleExport.dll
SetupProgID=SampleExport.Setup
SetupVersion=11.0
ReleaseModule=SampleExport.dll
ReleaseProgID=SampleExport
ReleaseVersion=11.0
SupportsNonImageFiles=True
SupportsKofaxPDF=True
Both your ReleaseScript.cs and ReleaseSetupScript.cs files need the correct attribute, for example:
[ProgId("SampleExport")]
public class ReleaseScript
If that all still does not work, please provide us with the detailed error message (to be found at CaptureSV\Logs).
I had to change the file format from UTF-8 to UTF-8 without BOM.
This worked for me.

Namespace autofill for custom attributes

I have a project "CustomViews" that I'd like to use as a library in another project "Library Dependent". One of my views, ToolbarITI has a few custom attributes defined in a file which I handle in my ToolbarITI class:
attrs.xml
<resources>
<declare-styleable name="ToolbarITI">
<attr name="rightIconSrc" format="integer"/>
<attr name="leftIconSrc" format="integer"/>
<attr name="titleText" format="string"/>
<attr name="iconPadding" format="dimension"/>
<attr name="fontName" format="string"/>
</declare-styleable>
</resources>
When I add the custom view to a layout in my Library Dependent project, I am able to add these custom attributes in the xml file, and the attributes are applied. However, Android Studio does not recognize the custom: attributes pertaining to ToolbarITI when auto-filling which makes the process annoying. I have declared xmlns:custom at the top of my layout file.
I simply do not understand how these attributes are bundled with the library project and referenced by Android studio. If anyone can explain how this is done, please do provide an explanation!
I'll need someone to confirm that this was the root of the problem, but this is what I found.
I was uploading my .aar to com.tommcfarlin.lib, which with the "lib" results in resources being ignored (according to Android Studio). Though I'm not sure if this results in anything "breaking" when packaging it certainly decreases the functionality of Android Studio by not adding resource ids for autofill. Better be safe and not do this.
These are the steps I took that resulted in Android Studio recognizing the custom attributes.
1) I altered my build.gradle in my CustomViews project to:
note the com.tommcfarlin.customviews
def aarFile = file("build/${archivesBaseName}-${project.version}.aar")
artifacts {
archives aarFile
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file:///C:/Users/tmcfarlin/AndroidProjects/myrepo")
pom.groupId = 'com.tommcfarlin.customviews'
pom.artifactId = 'CustomViews'
pom.version = '0.1.0'
}
}
}
2) I ran "gradle uploadArchives" from the terminal
3) In my Library Dependent project I had the following lines in my build.gradle:
repositories {
maven { url 'file:///C:/Users/tmcfarlin/AndroidProjects/myrepo' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.tommcfarlin.customviews:CustomViews:0.1.0#aar'
}
4) I synced the project with gradle files. After this, I still couldn't see the attributes. I closed the Library Dependent project and reopened it voila!!! I could now have the following block where my custom view's attributes were filled in for me when I typed "custom:" and pressed Ctrl+Space
<com.tommcfarlin.customviews.ToolbarITI
android:layout_width="wrap_content"
android:layout_height="wrap_content"
custom:fontName="helvetica.ttf">
</com.tommcfarlin.customviews.ToolbarITI>
This webpage has been immensely useful to me while learning how to set up a local repository. Just be sure not to use the "lib" directory!!! http://blog.glassdiary.com/post/67134169807/how-to-share-android-archive-library-aar-across

TFS and MSBuild projects Logging for each project

I'm going build large number (300+) of projects on TFS. I'm considering a proj file to manage these as follows:
<ItemGroup Label="GGX_Projects" >
<MyProj Include="$(Source)Proj1.vcxproj" />
<MyProj Include="$(Source)Proj2.vcxproj" />
<MyProj Include="$(Source)Proj3.csproj" />
<MyProj Include="$(Source)Proj4.csproj" />
<MyProj Include="$(Source)Proj5.vcxproj" />
<MSBuild Projects="#(MyProj)"
Targets="ReBuid"
Properties="Configuration='$(Configuration)'"
RebaseOutputs="true"
ContinueOnError="true"
/>
This actually working fine, but one thing I'm unable to achieve i.e. to get Log for each of the projects mentioned in ItemGroup.
I need separate logs, so that if any project fails, that log can be sent via e-mail.
In addition, on msbuild command line, I tried /distributedFileLogger, but unable to understand how to use this to get log file for each project separately.
Is that a correct approach?
Can anyone please suggest some better solution which could provide separate logging for each project??
Distributed file logger is, as the name suggests, for logging from individual MSBuild nodes within a "distributed" build system, not for logging from individual projects, targets or tasks. You can try creating a simple custom logger, it is fairly trivial, I've written a sample below. Although, you might want to play around with event types for verbosity and use something like NLog rather than appending to files as you might get locks.
msbuild PerProjectLogger.sln /logger:PerProjectLogger\bin\Debug\PerProjectLogger.dll
using System.Collections.Concurrent;
using System.IO;
using Microsoft.Build.Framework;
namespace PerProjectLogger
{
public class Logger : Microsoft.Build.Utilities.Logger
{
public override void Initialize(IEventSource eventSource)
{
var loggers = new ConcurrentDictionary<string, FileInfo>();
eventSource.AnyEventRaised += (s, a) =>
{
var property = a.GetType().GetProperty("ProjectFile");
if (property == null)
return;
var project = property.GetValue(a) as string;
if (project == null)
return;
var logger = loggers.GetOrAdd(Path.GetFileName(project), name => new FileInfo(name + ".log"));
using (var writer = logger.AppendText())
writer.WriteLine(a.Message);
};
}
}
}
The simplest way to achieve this with TFS is to create a single build detention and then on the Process tab you should see an option to pick solutions to build. Here you can add each Project individually. When you do a build the default build process will do a foreach project and build them. You will get a log file in the drop location for each project.

vs 2012: Shims compile

I am trying to make a shim in VS 2012 ultimate as it described in MSDN site:
[TestClass]
public class TestClass1
{
[TestMethod]
public void TestCurrentYear()
{
int fixedYear = 2000;
using (ShimsContext.Create())
{
// Arrange:
// Detour DateTime.Now to return a fixed date:
System.Fakes.ShimDateTime.NowGet =
() =>
{ return new DateTime(fixedYear, 1, 1); };
// Instantiate the component under test:
var componentUnderTest = new MyComponent();
// Act:
int year = componentUnderTest.GetTheCurrentYear();
// Assert:
// This will always be true if the component is working:
Assert.AreEqual(fixedYear, year);
}
}
}
see http://msdn.microsoft.com/en-us/library/hh549176.aspx
But when I compile my test project I get a notion in Output:
warning : Some fakes could not be generated. For complete details, set Diagnostic attribute of the Fakes element in this file to 'true' and rebuild the project.
How can I resolve this warning?
Visual Studio 2012 Update 1 improved code generation in Fakes to simplify troubleshooting of code generation problems. Whenever a Stub or a Shim could not be generated for a particular type, Fakes can now generate a warning message - you can see this in the Error List window of Visual Studio.
However, to prevent the number of warnings from becoming overwhelming for a large assembly, such as System, Fakes generates a single warning by default. You can see a complete list of warning messages by setting the Diagnostic attribute of the Fakes XML element in the .Fakes file to "true" or "1" and rebuilding the project. (See the first line of code below for an example.)
To resolve the warning, change the .Fakes file to generate only those Stubs and Shims you need in your tests. Details here
here a complete list of available options
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
<Assembly Name="System" Version="4.0.0.0"/>
<StubGeneration Disable="true" />
<ShimGeneration>
<Clear/>
<Add FullName="System.DateTime!"/>
</ShimGeneration>
</Fakes>
I have resolved it already alone.
It was .Net Framework 4.0 in Property.
Changing on 4.5 resolve the problem.
Try removing those .Fakes file.
I removed them accidentally and compiled, and the warnings are gone.
I am not sure what the impact is, but everything seems to run fine. I think it causes the compile to recompile the fakes file everything there is a build.

Resources