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

Auto-generate F# program file #1664

Merged
merged 7 commits into from
Jul 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/package/nuspec/Microsoft.NET.Test.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
Condition="'$(GenerateProgramFile)' == 'true'" />

<Target Name="CoreGenerateProgramFile"
Condition="'$(Language)'=='VB' or '$(Language)'=='C#'"
Condition="'$(Language)'=='VB' or '$(Language)'=='C#' or '$(Language)'=='F#'"
Inputs="$(MSBuildAllProjects)"
Outputs="$(GeneratedProgramFile)">

Expand All @@ -76,15 +76,31 @@
<Line Include="End Sub"/>
<Line Include="End Module"/>
</ItemGroup>

<ItemGroup Condition="'$(Language)'=='F#'">
<Line Include="// &lt;auto-generated&gt; This file has been auto generated. &lt;/auto-generated&gt;"/>
<Line Include="module AutoGeneratedProgram"/>
<Line Include="[&lt;EntryPoint&gt;]"/>
<Line Include="[&lt;Microsoft.VisualStudio.TestPlatform.TestSDKAutoGeneratedCode&gt;]"/>
<Line Include="let main _ = 0"/>
</ItemGroup>

<WriteLinesToFile
File="$(GeneratedProgramFile)" Lines="@(Line)" Overwrite="true" Encoding="Unicode">
</WriteLinesToFile>

<!--
Compile Include the generated Program File
-->
<ItemGroup>
<ItemGroup Condition="'$(Language)'!='F#'">
<Compile Include="$(GeneratedProgramFile)"/>
</ItemGroup>

<ItemGroup Condition="'$(Language)'=='F#'">
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

<ProgramCompiles Include="@(Compile)" Condition=" '%(Identity)' == 'Program.fs' "/>
<CompileAfter Include="$(GeneratedProgramFile)" Condition="@(ProgramCompiles-&gt;Count()) == 0"/>
</ItemGroup>

<Warning Condition=" @(ProgramCompiles-&gt;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 &lt;GenerateProgramFile&gt; property to 'false'." />
Copy link
Contributor

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.

</Target>
</Project>