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

Solution.AddAdditionalDocument does not add a new file with AdditionalFiles item type #4655

Open
vweijsters opened this issue Aug 19, 2015 · 21 comments

Comments

Projects
None yet
@vweijsters
Copy link

commented Aug 19, 2015

When adding a new file to a solution from within a codefix provider using the Solution.AddAdditionalDocument method, the file gets added with an item type of None where an item type of AdditionalFiles is expected.

This issue was observed using VS2015 RTM with roslyn 1.0.0

@Pilchie Pilchie added the Area-IDE label Aug 19, 2015

@jasonmalinowski

This comment has been minimized.

Copy link
Member

commented Aug 19, 2015

@vweijsters, can you clarify what your scenario is? What type of file is the file you're trying to add? I ask only because there's a few other bugs floating around in this area that might fix your underlying need and I'd like to confirm.

@vweijsters

This comment has been minimized.

Copy link
Author

commented Aug 19, 2015

I'm adding a default JSON settings file that will (in the future) be parsed by analyzers as means of configuration. The important part for me is that the added file will show up in the AnalyzerOptions.AdditionalFiles collection.

A first version of the code is available DotNetAnalyzers/StyleCopAnalyzers#1250
The codefix provider can be found here

@sharwell

This comment has been minimized.

Copy link
Member

commented Aug 20, 2015

👍

@Pilchie Pilchie added the Concept-API label Aug 20, 2015

@Pilchie Pilchie added this to the 1.1 milestone Aug 20, 2015

@jasonmalinowski

This comment has been minimized.

Copy link
Member

commented Aug 20, 2015

@vweijsters: thanks. In your case, the settings file name is always known, right? It's always stylecop.json?

@sharwell

This comment has been minimized.

Copy link
Member

commented Aug 21, 2015

@jasonmalinowski That's correct. It opens some possibilities regarding the inclusion of a .targets file in our NuGet package, but I was trying to avoid that.

@paul1956

This comment has been minimized.

Copy link
Contributor

commented Oct 24, 2015

@jasonmalinowski in my case I am adding a JSON file with a different name and still expect it to be an "AdditionalFile". I am adding it in a non-PCL project but want to read it in an Analyzer/Diagnostic using the Projects AdditionalFiles method which right now returns Nothing unless I hand edit the project file.

@paul1956

This comment has been minimized.

Copy link
Contributor

commented Oct 24, 2015

"Projects AdditionFiles method" above should read "AnalyzerOptions.AdditionalFiles collection". Can't correct on phone.

@twsouthwick

This comment has been minimized.

Copy link
Member

commented Nov 17, 2015

I'm encountering this as well (same scenario as @vweijsters). Any updates?

@jasonmalinowski

This comment has been minimized.

Copy link
Member

commented Nov 17, 2015

No updates, sorry.

@sharwell

This comment has been minimized.

Copy link
Member

commented Nov 26, 2015

@twsouthwick Take a look at how we are now handling this in DotNetAnalyzers/StyleCopAnalyzers#1790. Obviously it's not ideal, but it's enough to make sure that users aren't left with completely broken functionality 😄

@twsouthwick

This comment has been minimized.

Copy link
Member

commented Dec 3, 2015

Thanks @sharwell . We're already doing something similar to that. I was trying to add a codefix that would add a default config file so the VSIX version could be useful without requiring the user to open up the proj file.

@heaths

This comment has been minimized.

Copy link

commented Apr 23, 2016

Rather than try to change the nupkg so that AdditionalItems is used instead of None, why not just change how stylecop.json is found like some other tools (including NuGet) that search up from the project directory looking for it? That way, we can put a single stylecop.json in the solution root and all projects will use it automatically. If a project wants to override, have a project-local copy with changes. Lots of tools work this way, like git with .gitignore.

@Pilchie Pilchie modified the milestones: 2.0 (RC), 1.3 May 27, 2016

@Pilchie Pilchie modified the milestones: 2.0 (Preview 5), 2.0 (RC) Sep 26, 2016

@Pilchie Pilchie modified the milestones: 2.0 (RC), 2.0 (Preview 5) Sep 26, 2016

@jasonmalinowski jasonmalinowski modified the milestones: 2.0 (RC), 2.0 (RTM) Oct 19, 2016

@scott-xu

This comment has been minimized.

Copy link

commented Dec 3, 2016

@sharwell Can you please consider @heaths 's suggestion?

@sharwell

This comment has been minimized.

Copy link
Member

commented Dec 3, 2016

@heaths @scott-xu You are assuming that the project being analyzed exists on disk, and that the file system can be used to locate a file relative to the project. Neither of these are valid assumptions in a Roslyn analyzer.

The obvious counterexample is MetadataAsSourceWorkspace, but other useful cases can easily be described, such as analyzing the code in a specific Git commit without actually checking out that commit. The APIs that would allow analyzers to locate files within these virtual projects are not exposed to analyzers except as requested in this bug.

@StingyJack

This comment has been minimized.

Copy link

commented Jan 11, 2017

I was having this problem with the example CodeAnalyzer project and installing the analyzers I had made via nuget package. After wading through quite a few other project template related difficulties, I was able to get this to work by updating the nuget install.ps1 (that project template needs cleanup) to include the following at the end...

$item = $project.ProjectItems.Item("ForbiddenReferences.xml") 
$item.Properties.Item("BuildAction").Value = 4  

4 is the magic BuildAction for "AdditionalFiles", and it didnt require a project reload.

I'm not sure if this is useful to anyone, but going through this thread helped me get to this solution.

@danmendonca

This comment has been minimized.

Copy link

commented May 15, 2017

The workaround of this issue for what I am understanding (the above mentioned), depends on knowing the file name from the beginning. Has someone found another way? I guess this is low in the priority list.

@jnm2

This comment has been minimized.

Copy link
Contributor

commented Oct 15, 2017

I'm blocked on this too. I can't just update via NuGet tools because the path needs to be customized to the individual repository.

@RubenMateus

This comment has been minimized.

Copy link

commented Apr 11, 2018

Any news from this? Really would like to add style cop to project

@tpodolak

This comment has been minimized.

Copy link

commented Jul 18, 2018

Any updates on this one?

@gruckion

This comment has been minimized.

Copy link

commented Nov 21, 2018

This was started back in 2015 and it's still not closed? What is the progress of this item?

@jasonmalinowski jasonmalinowski modified the milestones: 16.0, Backlog Jan 17, 2019

@TannerBragg

This comment has been minimized.

Copy link

commented Apr 28, 2019

Any progress or update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.