2017-06-12 132 views
2

所以我確信我在做一些愚蠢的錯誤。我不確定它是什麼。從System.Diagnostics.Process運行時,dotnet運行失敗

如果我從終端運行以下命令一切正常。

~>dotnet run --project /path/to/my.fsproj 

然而,當我從下面的代碼的FSX文件運行該命令,我得到一個錯誤。

let dotnetRunNoArgs path = 
    let info = ProcessStartInfo(FileName = "dotnet", Arguments = sprintf "run --project %s " path) 
    let proc = new System.Diagnostics.Process(StartInfo = info) 
    start proc 
    proc 

let buildProcessStartInfoFCollectionTests = 
    dotnetRunNoArgs "/path/to/my.fsproj" 

buildProcessStartInfoFCollectionTests.Start() |> ignore 

錯誤:

/Users/username/.nuget/packages/fsharp.net.sdk/1.0.0/build/FSharp.NET.Core.Sdk.targets(122,9): 
error MSB4062: The "Fsc" task could not be loaded from the assembly 
/Users/username/.nuget/packages/fsharp.compiler.tools/4.1.0/build/netcoreapp1.0/FSharp.Build.dll. 
Assembly with same name is already loaded Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [/path/to/my.fsproj] 
/Users/username/.nuget/packages/fsharp.net.sdk/1.0.0/build/FSharp.NET.Core.Sdk.targets(122,9): 
error MSB4062: The "Fsc" task could not be loaded from the assembly 
/Users/username/.nuget/packages/fsharp.compiler.tools/4.1.0/build/netcoreapp1.0/FSharp.Build.dll. 
Assembly with same name is already loaded Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [/path/to/my.fsproj] 

The build failed. Please fix the build errors and run again. 
+0

也許你需要首先設置['CurrentDirectory'](https://msdn.microsoft.com/en-us/library/system.environment.currentdirectory(v = vs.110).aspx)? – kvb

+0

在Windows上,我有問題直接作爲進程運行一些程序。我不得不啓動'cmd',並將實際的可執行文件作爲參數傳遞。我不確定這是否有幫助! – TheQuickBrownFox

+0

@TheQuickBrownFox這是一個OS X環境 –

回答

1

錯誤結束了在fsproj文件之中。

的問題是,它需要有版本屬性上

<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" /> 
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0"/> 

而且,我需要從項目標籤去除xmlns="http://schemas.microsoft.com/developer/msbuild/2003"