-
Notifications
You must be signed in to change notification settings - Fork 326
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
Auto-generate F# program file #1664
Conversation
@@ -76,15 +76,26 @@ | |||
<Line Include="End Sub"/> | |||
<Line Include="End Module"/> | |||
</ItemGroup> | |||
|
|||
<ItemGroup Condition="'$(Language)'=='F#'"> | |||
<Line Include="module Program"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail if another module is named Program
. It would probably be better to do something like
module ``VSTest-AutoGenerated-Program``
It can still have collisions, but way less likely. Also, both the C# and the VB version is decorated with TestSDKAutoGeneratedCodeAttribute
which is probably a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - I'll fix that.
My "program" files are never called |
Yeah, but you still have the option to specify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saul Thanks a lot 👍 for PR.
<Compile Include="$(GeneratedProgramFile)"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(Language)'=='F#'"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure runtimeconfig.*.json
will gets generates because CompileAfter
?
FYI dotnet/sdk#201 #287.
@saul did you test simple unit test project of F# with your changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understood what is CompileAfter. Now it makes sense after reading issue one more time.
I have checked out your branch and verified E2E scenario. Below are the issue we need to address.
- Newly created F# unit test project not getting compiled because of below compilation error.
PS C:\Users\samadala\tmp\fs-test-project> dotnet test
Build started, please wait...
C:\Users\samadala\tmp\fs-test-project\Program.fs(1,1): error FS0222: Files in libraries or multiple-file applications must begin with a namespace or module declaration. When using a module declaration at the start of a file the '=' sign is not allowed. If this is a top-level module, consider removing the = to resolve this error. [C:\Users\samadala\tmp\fs-test-project\fs-test-project.fsproj]
This can be fixed by removing <Compile Include="Program.fs" />
from template fsproj here and removing Program.fs, We can address this with separate https://github.com/dotnet/templating PR
- Test project created with old templates fail to compile with above error on updating to latest
Microsoft.NET.Test.Sdk
package.
This can be fixed by adding check here that don't include GeneratedProgramFile
in CompileAfter
if Compile
item group contains Program.fs
.
@saul Can you please fix the seconds issue in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @smadala - I've fixed the second problem.
I've added a warning: A 'Program.fs' file can be automatically generated for F# .NET Core test projects. To fix this warning, either delete the file from the project, or set the <GenerateProgramFile> property to 'false'.
This lets the user either remove their Program.fs, or disables <GenerateProgramFile>
if they need a complex Program.fs for whatever reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saul Adding warning is very good idea.
Hi @smadala - I tested the changes with a unit test project I had and the Program.fs file was generated as expected and the tests passed. |
@saul Can you please test E2E? Add |
<CompileAfter Include="$(GeneratedProgramFile)" Condition="@(ProgramCompiles->Count()) == 0"/> | ||
</ItemGroup> | ||
|
||
<Warning Condition=" @(ProgramCompiles->Count()) != 0 " Text="A 'Program.fs' file can be automatically generated for F# .NET Core test projects. To fix this warning, either delete the file from the project, or set the <GenerateProgramFile> property to 'false'." /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might need localization. We will take it in separate PR if required.
@dotnet-bot test this |
@dotnet-bot test this |
Merged, great news! Will this be in the next VSTest release? |
Yes, this should be available in our next release of "Microsoft.NET.Test.Sdk" nuget. We will also insert the same in dotnet SDK |
Description
Allows F# Program.fs to be autogenerated.
Todo:
Related issue
Fixes #1171. cc @enricosada