Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModifyAssemblyInfo Add new method to retain existing assemblyinfo data #1027

Open
robgha01 opened this issue Jul 3, 2016 · 10 comments
Open

Comments

@robgha01
Copy link

robgha01 commented Jul 3, 2016

I want to modify an existing AssemblyInfo using the CreateAssemblyInfo it deletes all other info and no option exist to retain the values also ParseAssemblyInfo result can not parse directly to AssemblyInfoSettings for esey use,

I think it would be better to add one more function to the aliases named ex
ModifyAssemblyInfo or EditAssemblyInfo wich take in the same call parameters as CreateAssemblyInfo but only modifies and keeps the info that is not modified ?

@dbarkwell
Copy link

This would be useful. At the very least have AssemblyInfoParser return AssemblyInfoSettings.

@devlead
Copy link
Member

devlead commented Oct 20, 2016

As you can have multiple files with "assembly attributes" in a project I think the best solution/practice would be to have one file for auto generated code and one for manually maintained code.

@Tdue21
Copy link

Tdue21 commented Sep 14, 2017

No, the best solution would be to be able to modify a single file instead of having to change several hundred projects in order to link to a new file.

@devlead
Copy link
Member

devlead commented Sep 14, 2017

That's why I think having one shared file for all projects is the best middle ground.

@austinoriginal
Copy link

austinoriginal commented Sep 21, 2017

Its a significant effort to convert a solution or in my case many different solutions to use the shared single assemblyinfo.cs approach. I'd like to see a good solution to updating the FileVersion and AssemblyVersion attributes without touching anything else in an existing file. Is there a best practice around this today or do I just need to read each file and re-write them doing pattern matching and string replacement?

@devlead
Copy link
Member

devlead commented Sep 21, 2017

If you only want to touch certain attributes I would recommend having those in one file and the attributes you manually edit in a separate file.

Also worth noting with new 2017 project format you can set most of these properties via msbuild properties and keep the rest / default values in the csproj.

@robgha01
Copy link
Author

robgha01 commented Sep 28, 2019

I forgot about this issue but got remainded today while i tried to fix a strange bug in my system, long story short it was cused by a custom attribute that i have in my AssemblyInfo.cs file that the ioc system im using where looking for however like before the methods removed them took me a day of debugging to figure out way dependencies dide not get registered xD

I still stand for what i said before i need to use this attribute and am not intressted in more complexity for someting that should work out of the box. Also to note i have updated Cake to latest version 0.34.1 just to test out if this issue still existed from 0.22.0

Also ParseAssemblyInfo return type AssemblyInfoParseResult dont even have a CustomAttributes property.

@robgha01
Copy link
Author

Im looking at how things work and ParseAssemblyInfo is using regex matches for everyting after playing around with it i looked at the AssemblyInfoCreator anyway if anyone wants to try and make anyting work here is the fork: https://github.com/robgha01/cake

I made a test Should_Read_CustomAttributes in AssemblyInfoParserTests.cs
I dont see any way to fix this issue if this two things is not solved somehow also a attribute with a value not in the form of a string needs more handling for now i use "DataContractJsonSerializer" in AddCustomAttribute and the attribute value is changed from string to object. feal free to do anyting this was just me running wild to try and come up with someting.

@devlead
Copy link
Member

devlead commented Oct 1, 2019

As handling all corner cases of C# would take some effort perhaps it could be that using Roslyn would be better than Regex.

As this would be a decent amount of refactoring I personally believe best way would be to create an addin first as a PoC and once fully backed it could potentially be something we could lift in with lower risk after it's battle tested

Microsoft docs has some decent documentation on starting with Roslyn
https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/get-started/syntax-analysis

@robgha01
Copy link
Author

robgha01 commented Oct 1, 2019

@devlead I have started a PoC repo here https://github.com/robgha01/Cake.AssemblyInfo for now i can get the attributes using roslyn but there constructor info is empty xD

For now i have used this example here: https://stackoverflow.com/questions/57065238/getting-assembly-attributes-with-roslyn

Also im a total beginer when it comes to roslyn the main goal for now is try to actually get valid data out.

Edit: also found this https://joshvarty.com/learn-roslyn-now/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants