Wildcard file include in .NET Core project with F# - f#

I was trying out ASP.NET Core with F# using the aspnet Yeoman template, and I found something I didn't expect in project.json:
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"debugType": "portable",
"compilerName": "fsc",
"compile": {
"includeFiles": [
"Controllers.fs",
"Startup.fs",
"Program.fs"
]
}
If I move any of the existing files, I get a build error. If I change the includeFiles property to a single string with the value *.fs, I get the following message:
The 'includeFiles' property cannot contain wildcard characters.
The F# project templates from the dotnet CLI also include this structure in their project.json.
Having to add every single file to your project.json manually seems like a pretty big productivity impediment to using F# with .NET Core. Is there any way around this currently?

In F# you have to explicitly define the order in which source files are compiled.
So wildcard doesn't make sense in any F# build system.
A good blog post about Organizing modules and files

Related

How to change the MVC project fileĀ“s path for a ASP.NET core project using VS Core when implementing Areas

I have found out that I need to use Areas in asp.net core and the files arent recognized after they have changed the location, is there a file or extension that I should change-use in order for VS Code and the project to recognize the new location of the MVC files?
the original file's path would be like
~\ProjectName\ProjectName\Models
~\ProjectName\ProjectName\Controller
~\ProjectName\ProjectName\Views
when using areas should have a route like
~\ProjectName\ProjectName\Areas\Models
...
now I wonder if there was an easy way to change the file's path using vs code?
i tried editing launch.json but it doesnt recognize ViewModels folder
"sourceFileMap": {
"/Views": "${workspaceFolder}/Area/Views",
"/Controllers" : "${workspaceFolder}/Area/Controllers",
"/Models":"${workspaceFolder}/Area/Models",
"/ViewModels": "${workspaceFolder}/Area/ViewModels",
}```

How to use bundles like in old mvc

I'm migrating a old MVC application to new asp.net core and I'm dealing with the new bundleconfig.json and how it works.
In the old code I used to have something like this:
bundles.Add(new ScriptBundle("~/bundles/appcomponents").Include(
"~/Scripts/js/jquery.js",
"~/Scripts/js/bootstrap.js",
"~/Scripts/js/modernizr.js",
"~/Scripts/js/detect.js",
"~/Scripts/js/fastclick.js",
"~/Scripts/js/jquery.slimscroll.js",
"~/Scripts/js/jquery.blockUI.js",
"~/Scripts/js/waves.js",
"~/Scripts/js/wow.min.js",
"~/Scripts/js/jquery.nicescroll.js",
"~/Scripts/js/jquery.scrollTo.min.js"));
And in my CSHTML file I just added #Scripts.Render("~/bundles/appcomponents")
And I can had multiple bundles so depending on the view I could reference a different bundle depending on the files required for that module or view.
In Asp.Net Core I don't know how to do that.
I saw that you can add the files for CSS and JS but just once, like I don't see a way to have multiple bundles. In that case not all the modules uses the same CSS files and JS files so doesn't make sense to always pulls everything, what it makes more sense is to just use the required files for that module of view and thus from the bundleconfig.json a way to have multiple bundles just as in the old mvc projects.
[
{
"outputFileName": "wwwroot/css/main.min.css",
"inputFiles": [
"wwwroot/css/site.css",
"wwwroot/css/abc01.css"
]
},
{
"outputFileName": "wwwroot/js/main.min.js",
"inputFiles": [
"wwwroot/js/site.js",
"wwwroot/js/abc01.js"
],
"minify": {
"enabled": true,
"renameLocals": true
},
"sourceMap": false
}
]
Also, if I'm running based on development, can I just reference my script as:
<script src="~/js/main.min.js"></script>
Because I think main.min.js is only generated when building for production. So if that's correct, how do you reference when dev? Do I have to include in my views all the scripts and css using the Environment Include tag? and then use Environment exclude tag for the main.min.js?

Defining module names with Typescript

I'm trying to use TypeScript with RequireJS but I'm getting the following error:
Mismatched anonymous define() module.
I understand this is because Typescript is not emitting a module name and I'm loading the scripts into the page myself (I'm doing this as they are defined as a pre-defined bundle in the MVC project).
Currently the outputted .js looks like this:
define(["require", "exports", "jquery"], function(require, exports, $) {...
When I need it to emit:
define("MODULE_NAME" ["require", "exports", "jquery"], function(require, exports, $) {...
Is this possible with Typescript or should I look at replacing the bundle for minimization with Require.js's own optimization?
If you are using ASP.NET and the integrated script bundling, you are correct: The problem is that the bundle contains multiple anonymous modules. While it is good, common practice to work with anonymous modules (and let some compressor/optimizer do the naming later), this won't work for ASP.NET bundling because it only concatenates the input JS files. The solution is to make TypeScript create named modules. And this is possible with TS, so the answer to your question
Is this possible with Typescript
is definitely: Yes!
TypeScript 1.4 added the ability to emit AMD named modules to the compiler, like this:
///<amd-module name='NamedModule'/>
export class C {
}
The issue is not in the code generation (which is correct). The issue is that you probably have a script tag loading this JavaScript file. It should only be loaded by RequireJS, using data-main or as a dependency of another module.
See : http://requirejs.org/docs/errors.html#mismatch
Remove the script tag

Properties.Resources.XXXX Namespace or Module not Defined

I'm trying to read in the text (as a string) of an XML file from my Resources. The XML file is named MyXMLResourceFile.resx.
I tried using the C# way using
let myFile : string = Properties.Resources.MyXMLResourceFile
but it is giving me the error (under Properties):
The namespace or module 'Properties' is not defined.
I'm assuming I'm missing an open but have no idea what it would be.
Sorry, I'm still pretty new to F# coming from VB.
Additional information:
I made the resx file myself per this SO answer I then looked to see how others accessed it. In C# they did Properties.Resources.XXXX per this project I saw you could use ResourceManager but didn't see any method to read the whole file directly into a string.
The namespace or module 'Properties' is not defined.
That's because the namespace Properties is not defined. You probably brought the resx file from another project. Open the associated .Designer file, if it doesn't appear in the F# project, open it up in the original project. You will see a namespace with and a bunch of C# code, assuming the original project was in C#. The namespace of this file has to be the same namespace of the project where you are trying to call it.
But, since this is C# code, it won't run on a F# project. You have two choices: use a code generator to generate the associated .Designer class in F# code with the Properties namespace, (I don't know if such generator exists); or pre-compile the resx in the original project and reference it as a dll from your F# project, then you can access it with ResourceManager.

How to compile F# library from another F# program

I want to make my Application configuration as F# file wich will be compiled to dll. (like XMonad configuration with xmonad.hs on haskell). I found it more interesting and just better way then using XML serialization.
So is there any way how can I compile single file (or more) to Library with some configuration like
module RNExcel.Repository
open RNExcel.Model
type ExpenseReportRepository() =
member x.GetAll() =
seq{ yield {Name="User1"
Role="someRole"
Password = "123321"
ExpenseLineItems =
[{ExpenseType="Item1"
ExpenseAmount="50"};
{ExpenseType="Item2"
ExpenseAmount="50"}]}
yield {Name="User2"
Role="Estimator"
Password = "123123"
ExpenseLineItems =
[{ExpenseType="Item1"
ExpenseAmount="50"};
{ExpenseType="Item2"
ExpenseAmount="125"}]} }
my idea was to run shell .... and msbuild the project , but I don't think it will works for every user with .net 4
Check out the F# Power Pack, specifically the FSharp.CodeDom library. You can use this library to compile F# code at run-time and, with a little Reflection thrown in, can likely achieve your goal of code-as-configuration with minimal fuss.
I think that using CodeDOM provider from the PowerPack as Ben suggested is a way to go. I'd just like to add a few things (and it didn't fit into the comment box).
To parse and compile the F# code with the configuration, you need just to compile the source file that the users write using F# PowerPack. The compilation part of PowerPack is complete and works just fine. It invokes the F# compiler under the cover and gives you the compiled assembly back. The only problem is that the users of your application will need to have F# compiler installed (and not just the redist).
The incomplete part of F# CodeDOM provider is generating F# code from CodeDOM trees (because the trees were not designed to support F#), but that's not needed in this case.

Resources