2017-02-18 50 views
6

安裝在我的機器上是:奇怪的生成錯誤的.Net核心項目

  • 的Visual Studio Pro中2015年
  • 的Visual Studio 2015年更新3
  • .NET核心1.0.1工具預覽版2

注意:在Windows 10機器和Windows 7機器上會出現生成錯誤,但生成在另一臺Windows 7機器上可以正常工作。

所以我的git克隆從另一個開發一個.net核心項目,當我嘗試建立在Visual Studio 2015年我收到錯誤

「系統找不到Microsoft.DotNet.Common指定的文件。目標管線262"

圍棋在C行262:\程序文件(x86)\的MSBuild \微軟\ VisualStudio的\ v14.0 \ DOTNET的\ Microsoft.DotNet.Common.Targets線262我看到

<Dnx 
    RuntimeExe="$(SDKToolingExe)" 
    Condition="'$(_DesignTimeHostBuild)' != 'true'" 
    ProjectFolder="$(MSBuildProjectDirectory)" 
    Arguments="$(_BuildArguments)" 
    /> 

如果從Microsoft.DotNet.Common.Targets項目中刪除此部分建立。

我知道dnx是舊的.Net Core工具,我的猜測是類庫中的project.json的東西,遺留給舊的dnx工具以及我已安裝的新的1.0.1 Preview 2 .Net Core工具將舊的project.json條目推遲到Microsoft.DotNet.Common.Targets中的舊dnx工具條目,但由於我沒有安裝dnx工具,所以構建失敗,當然,這只是一個猜測。

我已經廣泛在網上搜索關於這個問題,我found an article說明把"type": "platform"Microsoft.NETCore.App依賴於project.json但我沒有使用依賴,我嘗試添加"type": "platform""NETStandard.Library"的依賴,但沒有幫助,在這裏是我project.json:

{ 
    "version": "1.0.1-*", 

    "dependencies": 
    { 
    "Microsoft.AspNetCore.Mvc.Abstractions": "1.1.0", 
    "Microsoft.AspNetCore.Mvc.Core": "1.1.0", 
    "NETStandard.Library": "1.6.1", 
    "TSO.ProductItemList.Model": "1.0.2" 
    }, 

    "frameworks": 
    { 
    "netstandard1.6": 
    { 
     "imports": "dnxcore50" 
    } 
    }, 

    "scripts": 
    { 
    "postcompile": 
    [ 
     "dotnet pack --no-build --configuration %compile:Configuration%", 
     "\"C:\\Program Files (x86)\\NuGet\\nuget\" push \"%project:Directory%\\bin\\%compile:Configuration%\\%project:Name%.%project:Version%.nupkg\" -s http://foo/NugetServer/ -apikey testkey" 
    ] 
    } 
} 

這裏是生成輸出:

1>------ Build started: Project: TSO.ProductItemList.Model, Configuration: Debug Any CPU ------ 
1> C:\Program Files\dotnet\dotnet.exe build "C:\projects\tsl\ProductItemList\src\TSO.ProductItemList.Model" --configuration Debug --no-dependencies 
1> Project TSO.ProductItemList.Model (.NETStandard,Version=v1.6) will be compiled because project is not safe for incremental compilation. Use --build-profile flag for more information. 
1> Compiling TSO.ProductItemList.Model for .NETStandard,Version=v1.6 
1> Producing nuget package "TSO.ProductItemList.Model.1.0.2" for TSO.ProductItemList.Model 
1> TSO.ProductItemList.Model -> C:\projects\tsl\ProductItemList\src\TSO.ProductItemList.Model\bin\Debug\TSO.ProductItemList.Model.1.0.2.nupkg 
1> Producing nuget package "TSO.ProductItemList.Model.1.0.2.symbols" for TSO.ProductItemList.Model 
1> TSO.ProductItemList.Model -> C:\projects\tsl\ProductItemList\src\TSO.ProductItemList.Model\bin\Debug\TSO.ProductItemList.Model.1.0.2.symbols.nupkg 
1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5): error : The system cannot find the file specified 
2>------ Build started: Project: TSO.ProductItemList.Client, Configuration: Debug Any CPU ------ 
2> C:\Program Files\dotnet\dotnet.exe build "C:\projects\tsl\ProductItemList\src\TSO.ProductItemList.Client" --configuration Debug --no-dependencies 
2> Project TSO.ProductItemList.Client (.NETStandard,Version=v1.6) will be compiled because project is not safe for incremental compilation. Use --build-profile flag for more information. 
2> Compiling TSO.ProductItemList.Client for .NETStandard,Version=v1.6 
2> Producing nuget package "TSO.ProductItemList.Client.1.0.1" for TSO.ProductItemList.Client 
2> TSO.ProductItemList.Client -> C:\projects\tsl\ProductItemList\src\TSO.ProductItemList.Client\bin\Debug\TSO.ProductItemList.Client.1.0.1.nupkg 
2> Producing nuget package "TSO.ProductItemList.Client.1.0.1.symbols" for TSO.ProductItemList.Client 
2> TSO.ProductItemList.Client -> C:\projects\tsl\ProductItemList\src\TSO.ProductItemList.Client\bin\Debug\TSO.ProductItemList.Client.1.0.1.symbols.nupkg 
2>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5): error : The system cannot find the file specified 
========== Build: 0 succeeded, 2 failed, 0 up-to-date, 0 skipped ========== 
+0

給VS 2017年一試。舊工具不再由Microsoft積極維護。 –

+0

@LexLi VS 2015被認爲是舊的工具?爲什麼是Microsoft Core安裝說明的第一步:「下載Visual Studio 2015」? https://www.microsoft.com/net/core#windowsvs2015 –

+0

只是因爲它還沒有3月7日。他們可能不想在這麼短的時間內更新兩次頁面。 –

回答

10

該錯誤消息完全是誤導性的,它是我的postcompile cmd將庫作爲nuget包發佈到我自己的nuget服務器,該服務器失敗:

"scripts": 
    { 
    "postcompile": 
    [ 
     "dotnet pack --no-build --configuration %compile:Configuration%", 
     "\"C:\\Program Files (x86)\\NuGet\\nuget\" push \"%project:Directory%\\bin\\%compile:Configuration%\\%project:Name%.%project:Version%.nupkg\" -s http://foo/NugetServer/ -apikey testkey" 
    ] 
    } 

即CMD試圖調用C:\Program Files (x86)\NuGet\nuget.exe

正如我所說的,我克隆該項目並沒有創造它,誰創造了這個項目的開發商已安裝C:\Program Files (x86)\NuGet\nuget.exe

我只有C:\Program Files (x86)\NuGet,沒有nuget.exe,該文件夾存在,因爲我安裝了Visual Studio 2015 nuget擴展,並且.vsix文件居住在那裏但沒有nuget.exe。

我只是下載nuget.exe here最新版本(V3.5.0)和放置在我的postcompile CMD希望它是:C:\ Program Files文件(x86)的\的NuGet

+1

很高興看到你找到原因,但推薦移動到最新的SDK作爲預覽版本即將過期。 –

+0

偉大的提示,也是我的原因。希望VS2017中的csproj能夠迴歸更好的SDK – ZoolWay

0

嘗試......

  1. 關閉Visual Studio的
  2. 下載SDK 1.1,https://www.microsoft.com/net/core#windowscmd
  3. 重新打開項目在Visual Studio
  4. 刪除project.lock.json(等待恢復)
  5. 重建
+0

我已經有.NET 1.1的核心安裝,我刪除了.json.lock,等待恢復和後續的構建仍然未能 –

+0

嘗試添加運行部分(下面的框架部分): –

+0

「運行環境」:{ 「win10-64」 :{} }, –