-
Notifications
You must be signed in to change notification settings - Fork 256
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
File New Project Analyzer does not build #514
Comments
cc @jmarolf |
@KSchlobohm We've recently made substantial changes to the analyzer templates. Can you clarify which version of Visual Studio you used to create the analyzer project? |
Visual Studio 2019 Version 16.6.0 Preview 4.0 |
This also applies to both the release version 16.6.0 and also version 16.7.0 Preview 1.0. As for the error with the test project, it has references to the following packages: <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.MSTest" Version="1.0.1-beta1.*" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.MSTest" Version="1.0.1-beta1.*" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing.MSTest" Version="1.0.1-beta1.*" /> But neither of these packages are published on NuGet. I was able to fix the references by adding the following to restore them from the preview feed: <PropertyGroup>
<RestoreAdditionalProjectSources>https://dotnet.myget.org/F/roslyn-analyzers/api/v3/index.json;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>
</PropertyGroup> But then I also had to fix the test by replacing the -using Verify = Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.MSTest.CodeFixVerifier<
+using Verify = Microsoft.CodeAnalysis.CSharp.Testing.MSTest.CodeFixVerifier<
AnalyzerTest.AnalyzerTestAnalyzer,
AnalyzerTest.AnalyzerTestCodeFixProvider>;
// …
- await Verify.VerifyCSharpDiagnosticsAsync(test);
+ await Verify.VerifyAnalyzerAsync(test);
// …
- await Verify.VerifyCSharpFixAsync(test, expected, fixtest);
+ await Verify.VerifyCodeFixAsync(test, expected, fixtest); This fixed the test project. As for the “Ambiguous project name 'Analyzer1'” error, I was able to fix that by changing the assembly name of the Vsix project: <PropertyGroup>
<TargetFramework>net472</TargetFramework>
<RootNamespace>Analyzer1.Vsix</RootNamespace>
- <AssemblyName>Analyzer1</AssemblyName>
+ <AssemblyName>Analyzer1Vsix</AssemblyName>
</PropertyGroup> But now when I’m building, I got this:
There is only one reference to .NET 4.5.2, so I changed that to match the target framework of the analyzer project: <ItemGroup>
<!-- https://github.com/dotnet/sdk/issues/433 -->
- <ProjectReference Update="@(ProjectReference)" AdditionalProperties="TargetFramework=net452" />
+ <ProjectReference Update="@(ProjectReference)" AdditionalProperties="TargetFramework=netstandard2.0" />
<!-- https://github.com/Microsoft/extendvs/issues/57 -->
<ProjectReference Update="@(ProjectReference)" Name="%(Filename)" />
</ItemGroup> With these changes, I was able to properly compile and debug the analyzer. Hope this helps anyone else struggling with this! |
@dotnet/project-system do you know of any way to test project templates in CI? |
@KeithLRobertson So far I'm still not aware of a great way to test the templates. However, I found a possible way to test the templates in #532 (the tests exist and can be run manually but currently don't run in CI). |
I think I have a similar problem with the "Code Refactoring (.NET Standard)" template using Microsoft Visual Studio Community 2019 The template creates 2 projects:
And the following error: The problem is that both created projects have the same assembly name "MyProjectName". As a workaround I changed the assembly name of the .Vsix project from "MyProjectName" to "MyProjectName.Vsix". I don't know if this has any other side effects but the nuget error is gone and everything else seems to work too. Would be nice if the official template could be adjusted. |
@sharwell which version of VS are the new templates in? |
They should be in the 16.7 release. |
@sharwell Is there any workaround yet without doing it manually? Updated template? Anything like that ? |
@MCCshreyas not yet. The template updates are coming in 16.7. |
@sharwell The same problem still exists with VB Analyzers |
@paul1956 I fixed both the C# and the VB templates at the same time, so they'll eventually get updated in the distribution for 16.7. |
I have tried using "Analyzer with Code Fix (.NET Standard)" template from latest preview of Visual Studio 16.7.0 Preview 4.0 and the new project dialog fails. Clicking on
Empty folder gets created on the disk, but without any project files. |
@nenadvicentic did you find a solution ? |
I reported this via Feedback yesterday, it reappeared with Preview 6. Workaround is don't use preview. But then the Analyzer doesn't build. |
@paul1956 @kofifus That was my solution as well, not to use Preview version at all. Still, there is a problem even with the stable version of VS. It uses outdated/never-officially-published Nuget packages for testing of those components and the template needs fixing of old pre-stable-release syntax. At the end I've built stand-alone console application to do the analysis/refactoring, which is not ideal. Hopefully MS guys provide stable way forward for developing (and testing) analyzers and code fixes for Visual Studio. Current situation is pretty bad and it's shame, because compiler itself is fully capable. |
@paul1956 The workaround is to use the preview version with the following sequence:
|
Thanks, is there a reason this is closed when in fact it does not work? |
The issue is assigned to an internal team. The templates were working fine in earlier 16.7 previews, prior to an unrelated product regression. |
Also note that this bug is marked fixed because the original issue #514 (comment) is fixed. The unrelated issue was just a follow-up comment in #514 (comment). |
@sharwell I tried your suggestion above about creating a blank solution and adding the project from template, while creating the project I get: Any help please ? I really need this, is there a way for you to provide a clean solution/project to start from ? that would be helpful |
@sharwell workaround worked for VB but the project has a hard reference to System.Collections.Immutable 1.2.5 and doesn't run with 1.7.0 this is probably a separate issue but not sure where to enter it, Roslyn, .Net Core, somewhere else? |
update - for VS19 16.8.0 preview 1.0
Solution now builds and run fine |
@kofifus For me, it is not necessary to do this step. Can you open a new issue for this?
@nenadvicentic This is a project system bug being investigated here:
@paul1956 Can you open a new issue for this? It sounds unrelated to the other issues here. |
Hi are there any news about this ? is there any way to get a template that builds with the tests running for latest VS19 preview ? |
@kofifus The path error is fixed for 16.8 Preview 2. The workaround from #514 (comment) can be used in the meantime. For other problems, see #583 (comment) for the current status. |
Thanks @sharwell, until it is all released is there a way for you to provide a download of a solution with a project based on the C# codefix template that builds and runs all tests ? I am no successful in creating that |
@kofifus Can you create a new issue for the specific problem you are encountering? |
For reference to future Googlers, this feed does not exist anymore. You now need to add the following feeds:
(It's likely only one of them is needed, but I didn't investigate further) Edit by @sharwell : I crossed out the unnecessary ones. 😄 |
Repro steps
Expected behavior
Actual behavior
The text was updated successfully, but these errors were encountered: