GithubHelp home page GithubHelp logo

304notmodified / fody.stamp Goto Github PK

View Code? Open in Web Editor NEW
65.0 4.0 19.0 2.12 MB

:octocat: Stamps an assembly with git data

License: MIT License

C# 98.25% PostScript 1.75%
fody git ilweaving versioning dotnet msbuild

fody.stamp's Introduction

NuGet Status Build status

Icon

This is an add-in for Fody

Stamps an assembly with git data.

The nuget package

https://nuget.org/packages/Stamp.Fody/

PM> Install-Package Stamp.Fody

Add to FodyWeavers.xml

Add <Stamp/> to FodyWeavers.xml

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <Stamp />
</Weavers>

What it does

Extracts the git information from disk, combines it with the assembly version, and places it in the AssemblyInformationalVersionAttribute.

So if your assembly version is 1.0.0.0, the working branch is master and the last commit is 759e9ddb53271dfa9335a3b27e452749a9b22280 then the following attribute will be added to the assembly.

[assembly: AssemblyInformationalVersion("1.0.0.0 Head:'master' Sha:759e9ddb53271dfa9335a3b27e452749a9b22280")]

Templating the version

You can customize the string used in the AssemblyInformationalVersionAttribute by adding some tokens to the string, which Stamp will replace.

For example, if you add [assembly: AssemblyInformationalVersion("%version% Branch=%branch%")] then Stamp will change it to [assembly: AssemblyInformationalVersion("1.0.0.0 Branch=master")]

The tokens are:

  • %version% is replaced with the version (1.0.0.0)
  • %version1% is replaced with the major version only (1)
  • %version2% is replaced with the major and minor version (1.0)
  • %version3% is replaced with the major, minor, and revision version (1.0.0)
  • %version4% is replaced with the major, minor, revision, and build version (1.0.0.0)
  • %now% is replaced with the current short date
  • %utcnow% is replaced with the current utc short date
  • %githash% is replaced with the SHA1 hash of the branch tip of the repository
  • %shorthash% is replaced with the first eight characters of %githash%
  • %branch% is replaced with the branch name of the repository
  • %haschanges% is replaced with the string defined in the ChangeString attribute in the configuration, see below.
  • %user% is replaced with the current user name
  • %machinename% is replaced with the current machine name
  • %lasttag% -is replaced with the last git tag in this branch.

NOTE: if you already have an AssemblyInformationalVersion attribute and it doesn't use replacement tokens, it will not be modified at all.

Configuration

All config options are attributes of <Stamp /> element in FodyWeavers.xml

ChangeString

Define the string used to indicate that the code was built from a non clean repository.

Default is HasChanges

<Stamp ChangeString="New text" />

UseProjectGit

Define if you want to start Stamp to start searching for the Git repository in the ProjectDir (true) or the SolutionDir (false).

Default is false (SolutionDir)

<Stamp UseProjectGit='true' />

Icon

Stamp designed by Rohith M S from The Noun Project.

fody.stamp's People

Contributors

304notmodified avatar davidalpert avatar distantcam avatar kzu avatar ldv2001 avatar mkaput avatar philippbeckmann avatar qmfrederik avatar simoncropp avatar yufeih avatar yura-yaroshevich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fody.stamp's Issues

Fails when two tags point to the same commit

Fody 2.4.6, Stamp.Fody 1.4.2

LibGitEx.FindVersionTag throws if two tags have the same commit, when trying to put them into a dictionary.

I'll probably just try to get rid of the extra tag, if not would you like a PR?

Fody: An unhandled exception occurred:
Exception:
An item with the same key has already been added.
Type:
System.ArgumentException
StackTrace:
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at LibGitEx.FindVersionTag(Repository repository) in C:\projects\fody-stamp\Fody\LibGitEx.cs:line 18
   at FormatStringTokenResolver.ReplaceTokens(String template, ModuleDefinition moduleDefinition, Repository repo, String changestring) in C:\projects\fody-stamp\Fody\FormatStringTokenResolver.cs:line 37
   at ModuleWeaver.Execute() in C:\projects\fody-stamp\Fody\ModuleWeaver.cs:line 71
   at lambda_method(Closure , Object )
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 200
   at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 102

Stamp dies unexpectedly on OSX / Mono

I configured and installed Stamp via nuget on a windows 7 / VS 2013 machine. We are targeting Mono 3.5 for a Unity project.

My colleague, developing on OSX 10.10.x, encounters the following error on build.

Target FodyTarget:
    Fody: Fody (version 1.29.3.0) Executing
    Fody: ProjectDirectory: '/repos/TCG_CS_Engine/'.
    Fody: AssemblyPath: '/repos/TCG_CS_Engine/obj/Debug/TCG_CS_Engine.dll'
    Fody: Found path to weavers file '/repos/TCG_CS_Engine/FodyWeavers.xml'.
    Fody: Found path to weavers file '/repos/TCG_CS_Engine/FodyWeavers.xml'.
    Fody: SolutionDirectory path is '/repos/TCG_CS_Engine/'
    Fody: Finding weavers
    Fody: Adding weaver dlls from '/repos/TCG_CS_Engine/Packages'.
    Fody: Fody weaver file added '/repos/TCG_CS_Engine/Packages/NameOf.Fody.0.8.4/NameOf.Fody.dll'
    Fody: Fody weaver file added '/repos/TCG_CS_Engine/Packages/PropertyChanged.Fody.1.48.2.0/PropertyChanged.Fody.dll'
    Fody: Fody weaver file added '/repos/TCG_CS_Engine/Packages/Stamp.Fody.1.2.0/Stamp.Fody.dll'
    Fody: Could not find packages dir from nuget config.
    Fody: SolutionDirectoryPath: /repos/TCG_CS_Engine/
    Fody: Adding weaver dlls from '/repos/TCG_CS_Engine/packages'.
    Fody: Fody weaver file added '/repos/TCG_CS_Engine/packages/NameOf.Fody.0.8.4/NameOf.Fody.dll'
    Fody: Fody weaver file added '/repos/TCG_CS_Engine/packages/PropertyChanged.Fody.1.48.2.0/PropertyChanged.Fody.dll'
    Fody: Fody weaver file added '/repos/TCG_CS_Engine/packages/Stamp.Fody.1.2.0/Stamp.Fody.dll'
    Fody: SolutionDirectoryPath: /repos/TCG_CS_Engine/
    Fody: Skipped scanning '/repos/TCG_CS_Engine/Tools' for weavers since it doesn't exist.
    Fody: No Weaver project file found.
    Fody: Finished finding weavers 47ms
    Fody: Creating a new AppDomain
    Fody: Reference count=7
    Fody: Found debug symbols at '/repos/TCG_CS_Engine/obj/Debug/TCG_CS_Engine.dll.mdb'.
    Fody: Weaver '/repos/TCG_CS_Engine/Packages/Stamp.Fody.1.2.0/Stamp.Fody.dll'.
    Fody:   Initializing weaver
    Fody:   Loading '/repos/TCG_CS_Engine/Packages/Stamp.Fody.1.2.0/Stamp.Fody.dll' from disk.
    Fody: Weaver '/repos/TCG_CS_Engine/Packages/PropertyChanged.Fody.1.48.2.0/PropertyChanged.Fody.dll'.
    Fody:   Initializing weaver
    Fody:   Loading '/repos/TCG_CS_Engine/Packages/PropertyChanged.Fody.1.48.2.0/PropertyChanged.Fody.dll' from disk.
      Fody/Stamp:   Executing Weaver 
      Fody/Stamp:   Starting search for git repository in SolutionDir
: error : Fody: An unhandled exception occurred:
Exception:
An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods
StackTrace:
  at LibGit2Sharp.Core.Proxy+<>c__DisplayClass30.<git_repository_discover>b__2f (LibGit2Sharp.Core.Handles.GitBuf buf) [0x00000] in <filename unknown>:0 
  at LibGit2Sharp.Core.Proxy.ConvertPath (System.Func`2 pathRetriever) [0x00000] in <filename unknown>:0 
  at LibGit2Sharp.Core.Proxy.git_repository_discover (LibGit2Sharp.Core.FilePath start_path) [0x00000] in <filename unknown>:0 
  at LibGit2Sharp.Repository.Discover (System.String startingPath) [0x00000] in <filename unknown>:0 
  at ModuleWeaver.Execute () [0x00000] in <filename unknown>:0 
  at (wrapper dynamic-method) object:lambda_method (System.Runtime.CompilerServices.Closure,object)
  at InnerWeaver.ExecuteWeavers () [0x00000] in <filename unknown>:0 
  at InnerWeaver.Execute () [0x00000] in <filename unknown>:0 
Source:
Stamp.Fody
TargetSite:
Int32 <git_repository_discover>b__2f(LibGit2Sharp.Core.Handles.GitBuf)
git2-90befde
StackTrace:
  at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init ()
  at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0 
  at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0 
Source:
Stamp.Fody
TargetSite:
Void .ctor()

    Fody:   Finished Fody 662ms.
 Task "Fody.WeavingTask" execution -- FAILED
 Done building target "FodyTarget" in project "/repos/TCG_CS_Engine/TCG_CS_Engine.csproj".-- FAILED

Done building project "/repos/TCG_CS_Engine/TCG_CS_Engine.csproj".-- FAILED

any advice would be greatly appreciated.

MSBUILD : error : Fody: Found no debug symbols.

Hi,
When I install this library by NuGet, I can build my project under Debug mode.
But when I switch to release mode, I encounter the mentioned error.

1>Using "Fody.WeavingTask" task from assembly "MyCore\Solution\packages\Fody.2.0.3\build\netstandard1.4....\Fody.dll".
1>Task "Fody.WeavingTask"
1> Fody: Fody (version 2.0.3.0) Executing
1> Fody: ProjectDirectory: 'MyCore\My.Common'.
1> Fody: AssemblyPath: 'MyCore\My.Common\obj\Release\My.Common.dll'
1> Fody: Found path to weavers file 'MyCore\My.Common\FodyWeavers.xml'.
1> Fody: SolutionDirectory path is 'MyCore\Solution'
1> Fody: Finding weavers
1> Fody: Adding weaver dlls from 'MyCore\Solution\Packages'.
1> Fody: Fody weaver file added 'MyCore\Solution\Packages\Stamp.Fody.1.4.2\Stamp.Fody.dll'
1> Fody: Could not find packages dir from nuget config.
1> Fody: SolutionDirectoryPath: MyCore\Solution
1> Fody: Adding weaver dlls from 'MyCore\Solution\packages'.
1> Fody: Fody weaver file added 'MyCore\Solution\packages\Stamp.Fody.1.4.2\Stamp.Fody.dll'
1> Fody: SolutionDirectoryPath: MyCore\Solution
1> Fody: Skipped scanning 'MyCore\Solution\Tools' for weavers since it doesn't exist.
1> Fody: No Weaver project file found.
1> Fody: Finished finding weavers 11ms
1> Fody: Creating a new AppDomain
1> Fody: Reference count=23
1>MSBUILD : error : Fody: Found no debug symbols.
1> Fody: Finished Fody 141ms.
1>Done executing task "Fody.WeavingTask" -- FAILED.

Cannot stamp an assembly whose project folder name or configuration name contains spaces

Hello,

When stamping one of my projects with a folder name like "blueprints-core (.NET 4.0)"
and a configuration name like "Release (.NET4.0 Client)" I got this:

[Fody.WeavingTask] Fody: Failed to apply product version to Win32 resources.
Output: error parsing product version arg
bad product version arg, see usage (/?)

Workaround:
Rename project folder name and configuration so that they do not contain spaces.
ie: "blueprints-core-NET4.0" AND "ReleaseClient"

Ownership

Hi @SimonCropp!

I'm thinking to volunteer for the ownership (if someone else is also interested, please reply - I like working in teams!)

Could we arrange a transfer of your knowledge (how to build, how to publish, (build) scripts, which projects to edit, caveats etc?) - on chat or mail?

Possible bug in ModuleWeaver.AfterWeaving()

I'm working on #13. In ModuleWeaver.AfterWeaving(), I see:

fixedFileInfo.ProductVersion = assemblyVersion;

but then:

stringTable.Values["ProductVersion"] = assemblyInfoVersion;

Is it intentional that these two are set to different values? If not, I can fix this while I'm in here.

COMPANY_NAME, COPYRIGHT and PRODUCT_NAME are being lost as verpatch.exe is not used in patch mode.

Hi,

We seem to be loosing company name, copyright and product name when using Fody.Stamp to set AssemblyInformationalVersionAttribute.

It seems the call to verpatch.exe includes "/va" which indicates it is in replace rather than patch mode.
This seems to cause COMPANY_NAME, COPYRIGHT and PRODUCT_NAME to be lost.

To see this in action run the unit tests and navigate to the directory AssemblyToProcessExistingAttribute\bin\Debug\

In windows explorer right click on the modified dll (AssemblyToProcessExistingAttribute2.dll) and select Properties/Details. When run on windows 7 we can observed that the product name has been wiped and copyright has been set to "Copyright (c) 2009"

It would be useful if Fody.Stamp could run verpatch in patch mode so old values are not lost.

If the code is modified to remove the "/va" and the tests re run the Properties/Details show the correct values.

Stamp failing on build server

Stamp works fine locally, but is failing on the server.

http://teamcity.ginnivan.net/viewLog.html?buildId=2727&buildTypeId=bt40&tab=buildLog#_focus=64

[10:01:03][Fody\Fody.csproj] WinFodyTarget (1s)
[10:01:03][WinFodyTarget] Fody.WeavingTask (1s)
[10:01:03][Fody.WeavingTask] Fody (version 1.14.0.0) Executing
[10:01:04][Fody.WeavingTask] Fody/Stamp: No .git directory found.
[10:01:04]
[Fody.WeavingTask] Fody: Failed to apply product version to Win32 resources.
Output: error parsing product version arg
bad product version arg, see usage (/?)

Error:
[10:01:04][Fody.WeavingTask] Finished Fody 1124ms.
[10:01:04][Fody\Fody.csproj] Project Fody\Fody.csproj failed.

Stamp.Fody replaces AssemblyFileVersion with AssemblyVersion

When using Stamp.Fody (1.2.2 w/ Fody 1.29.3) on a project that has both AssemblyVersion and AssemblyFileVersion specified, AssemblyFileVersion gets overwritten by the AssemblyVersion.

In some cases, this is a problem, as we often have an AssemblyVersion that only uses the major and minor version numbers (in order to preserve binary compatibility when there are no breaking changes), while the AssemblyFileVersion is the actual full version including the patch number.

1.4 is broken - Expression must be writeable

Unfortunately, there is a change that broke it.

On build we get:

Error		Fody: An unhandled exception occurred:
Exception:
Expression must be writeable
Parameter name: left
StackTrace:
   at System.Linq.Expressions.Expression.RequiresCanWrite(Expression expression, String paramName)
   at System.Linq.Expressions.Expression.Assign(Expression left, Expression right)
   at PropertyDelegateBuilder.TryBuildPropertySetDelegate[T](Type targetType, String propertyName, Action`2& action) in C:\projects\fody\FodyIsolated\DelegateBuilders\PropertyDelegateBuilder.cs:line 23
   at DelegateBuilder.BuildDelegateHolder(Type weaverType) in C:\projects\fody\FodyIsolated\DelegateBuilders\DelegateBuilder.cs:line 31
   at DelegateBuilder.GetDelegateHolderFromCache(Type weaverType) in C:\projects\fody\FodyIsolated\DelegateBuilders\DelegateBuilder.cs:line 15
   at InnerWeaver.InitialiseWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 127
   at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 82
Source:
System.Core
TargetSite:
Void RequiresCanWrite(System.Linq.Expressions.Expression, System.String)	

The weaver assembly references an out of date version of Mono.Cecil.dll when using Fody 3

We got the following exception when using Fody 3

Fody: The weaver assembly 'Stamp.Fody, Version=1.3.1.0, Culture=neutral, PublicKeyToken=null' references an out of date version of Mono.Cecil.dll. Expected strong name token of '1C-A0-91-87-7D-12-CA-03' but got '50-CE-BF-1C-CE-B9-D0-5E'. The weaver needs to update to at least version 3.0 of FodyHelpers.

The process cannot access the file mydll.dll.tmp because it is being used by another process.

Exception:

The process cannot access the file 'C:\project\obj\Debug\mydll.dll.tmp' because it is being used by another process.
StackTrace:
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at InnerWeaver.ReadModule() in C:\projects\fody\FodyIsolated\ModuleReader.cs:line 22
   at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 93
Source:
mscorlib
TargetSite:
Void WinIOError(Int32, System.String)	

this seems to be fixed in Fody/Fody#304

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.