Closed ThePhantasm closed 8 years ago
@ThePhantasm thanks for reporting the issue but I couldn't repeat the issue with Xamarin on Mac (I don't have VS 2015).
If you remove the first line (), does the issue go away?
If you clone this project, can you open samples/server/petstore/aspnet5/IO.Swagger.sln
?
No - that .sln fails to open as well. I'm checking to see if it's possibly a missing set of updates to VS 2015.
Nope - same issue. VS2015 says that the solution file is corrupt.
If you've time, please download Xamarin to give it a try to see if the issue is "Windows" only.
cc @jimschubert
@ThePhantasm can you post your VS 2015 version info? When I last worked on the aspnet5 generator, I seem to recall that I opened the project by the solution file in VS 2015. However, I rarely use Windows so I can go for weeks or months without boring into my VM or updating Visual Studio. If like to evaluate against the same version.
Also, a couple of other questions... Do you have any non-English language settings on your machine? Have you tried against swagger-codegen 2.2.0?
Visual Studio 2015 - 14.0.25424.00 Update 3 I tried against swagger-codegen 2.2.0 as well. Same issue. I'll try Xamarin now.
Aha, I think I have it! The issue is that the generated solution file is missing the project hash in its declaration.
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.xproj", "" EndProject
The "" is what is causing VS to choke. It needs the project hash (which is written below in the project) in the ""
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.xproj", "{3B5990B3-40F1-4148-89B5-84AC71432557}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {3B5990B3-40F1-4148-89B5-84AC71432557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Manually adding that hash into the quote marks lets VS load the solution. Of course, then it fails to load the .xproj - but I'll debug that as well.
Ok, the .xproj has the same basic issue as the solution file - missing guid. The shipped .xproj with 2.2.0 has this line in the .xproj
<PropertyGroup Label="Globals">
<ProjectGuid></ProjectGuid>
That guid needs to be filled out for Visual Studio to be able to load the files.
If someone can point me at the roughly approximate file that generates these files, I'm happy to update the code and submit a patch.
@ThePhantasm thanks for offering help to fix the issue. Here are the location of the files:
@ThePhantasm may I know if you've a chance to work on the fix? Do you need any help from us (the community)?
Actually yes. I looked at the mustache files, and from inspection - they look correct. Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{packageName}}", "src{{packageName}}{{packageName}}.csproj", "{{packageGuid}}"
My guess is that packageGuid is not being determined by the time it is being interpolated. I could hook a debugger up and try and trace it - but I don't know when I'll get time to do that.
@ThePhantasm sorry it took so long to get back to you on this issue. My wife and I had our second child on September 2, and I'm just now getting back into personal projects and open source contributions.
Your investigation really helped. {{projectGuid}}
isn't defined, so this was a typo on my part. There are details in the PR's commit about how this bug came into being (pretty much, I implemented the xproj support incorrectly and VS temporarily fell back to project.json and no longer does this). I've also cleaned up a couple of other issues (removed hard-coded src
project, set root namespace).
@wing328 @ThePhantasm would you mind verifying #3954? I've tested the change in JetBrains Rider and VS 2015 Community Edition. Rider has no issues loading and building, VS 2015 warns about a property on solution load. The VS 2015 warning doesn't prevent compilation (I assume a property in project.json is no longer supported).
I just tried it and VS 2015 still refuses to open the sln file.
@ogreenz can you verify whether Swagger Codegen compiled successfully? The first couple of times I compiled against the 2.3.0 branch, the generator project failed and I had to run mvn install
before building again.
Also, can you diff the generated sln against the one in master? The sln previously had two UTF-8 BOM characters, which caused the problem. It should have one or none.
@jimschubert I used the build instructions on the README. it just said clone and run mvn clean package
I did that and followed the instructions to generate a solution from my .json file. Also I don't know how it updates but the site swagger produces the same faulty .sln file. About the diff, what file am I suppose to diff with?
@ogreenz I don't know if editor.swagger.io is automatically deployed from master, and this change was merged less than 12 hours ago.
To rule out environment issues, you could run there generator using my swagger codegen cli docker image: https://hub.docker.com/r/jimschubert/swagger-codegen-cli/
I will also check later to see if the xproj and sln are generating the BOM inconsistently on master.
Also, could you provide details about your OS? I'm building in OS X El Capitan, and the generated files from my branch opened in VS2015 Community in Windows 10 and Rider EAP in OS X. What is your machine's primary language configured to?
I'm having problems using your docker (i'm just new to docker and it gives me a hard time with paths for some strange reason). but I'm using windows 10 VS 2015U3 and I cloned and build the project all over again just to make sure. my generated sln file is:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AFF6BF88-8A7D-4736-AF81-31BCE86B19BD}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.xproj", "{EB4D92DE-EE30-4D37-958A-21AB935F7151}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EB4D92DE-EE30-4D37-958A-21AB935F7151}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB4D92DE-EE30-4D37-958A-21AB935F7151}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB4D92DE-EE30-4D37-958A-21AB935F7151}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB4D92DE-EE30-4D37-958A-21AB935F7151}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
as you can see it still generates the BOM. deleting it doesn't help it open though.
Ok so the problem was the .sln and the .xproj files are still generated with BOMs. Now it works for me.
@ogreenz awesome. If you're generating locally, also try the following before generating your code:
set JAVA_OPTS=-Dfile.encoding=UTF-8
I've just built fully under Windows 10 and generated the aspnet 5 sample in Windows. I get the solution failing to open without setting the file.encoding
property explicitly, but no issue when it is set.
@wing328 We may want to consider updating the docs to include -Dfile.encoding=UTF-8
so Windows users don't have such issues with one or more generators. This will probably save some headaches for non-Windows users with default encodings of UTF-16 (I'm assuming, I haven't played around with UTF-16 environments much).
@jimschubert totally agree that Windows 10 users should be informed. I've updated https://github.com/swagger-api/swagger-codegen/wiki/Server-stub-generator-HOWTO#aspnet-5-web-api for the time being.
Another suggestion is to log a message via LOGGER.info so that users may catch the message.
Ideally we may want to detect the environment to set the file encoding to UTF-8 programmatically if it's a Windows10 machine but it may be a bit overkill and setting the file.encoding automatically based on OS may not work under different Windows10 settings.
Got it. Do you know if there's a way to just specify this when the files are being written? It would be nice to define the encoding per supporting file.
@jimschubert not off the top of my head. Will need to dig deeper into the code base to find out.
@jimschubert totally agree that Windows 10 users should be informed. I've updated https://github.com/swagger-api/swagger-codegen/wiki/Server-stub-generator-HOWTO#aspnet-5-web-api for the time being.
I'm not intimately familiar with java but this didn't work for me with openjdk 17.0.7.
Since this discussion is from 2016, chances are that the environment variable name has changed. Setting JAVA_TOOL_OPTIONS
before calling java does the trick though.
In power shell that would boil down to $env:JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF-8"
Description
[codegen] [aspnet5] codegen for aspnet5 consistently produces incorrectly solution file
Solution file starts with:  Microsoft Visual Studio Solution File, Format Version 12.00
Swagger-codegen version
swagger-codegen-cli-2.2.1 (likely a regression)
Swagger declaration file content or url
I can post the json I used, but the sample from http://editor.swagger.io/#/ produces the same error
(attempting to open the solution generated from that website has the same incorrectly formatted solution file)
Command line used for generation
java -jar C:\tmp\swagger-codegen-cli-2.2.1.jar generate -i c:\git\swagger.json -l aspnet5 -o c:\git\aspnet5
Steps to reproduce
Go to http://editor.swagger.io/#/ Generate an aspnet5 project. Open the zip, attempt to open the .SLN file with Visual Studio 2015