2017-03-21 53 views
14

我有框架的目標是.NET Framework 4.6.1一個項目,因爲在TFS持續集成過程的一部分,我們創建了一個生成解決方案的任務,以確保代碼編譯正確。
現在TFS服務器具有最新版本的.Net Famework 4.6.2的。在寄存器這是爲框架

On all other OS versions: 394806 => .NET Framework 4.6.2

不過的釋放鍵的值時,構建運行它配備了這個錯誤:

Error CS1056: Unexpected character '$' 

我不想替換字符串插值string.Format要解決此問題,請提供另一種解決方法來解決此問題。

我是否需要安裝TFS服務器上別的東西嗎?

+0

服務器上運行的是什麼版本的MSBuild? –

+0

您需要更新'MSBuild'工具,而不是'.NET'框架 – VMAtm

+0

@VMAtm我該怎麼做?我剛剛下載https://www.microsoft.com/en-us/download/details.aspx?id=48159,那是一個失敗 – Heinrich

回答

11

問題可以固定安裝NuGet包 Microsoft.Net.Compilers。下面是我的回答突出的鏈接:Project builds fine with Visual Studio but fails from the command line

That feature is a syntactic sugar for C#6, try to install the latest version of the framework 4.6.2 https://www.microsoft.com/en-us/download/details.aspx?id=53345

Then go to your Project properties and change on the Application option on Target framework to point to the latest. You don't need to change your code to replace the string interpolation with string.Format method to fix it. If you are still getting this error, is because, the compiler that is running your build is not the latest version of C#, try to add the Microsoft.Net.Compilers, from Nuget and compile again, that should resolve the issue. If you want to avoid to install this package, try to open your .csproj and take a look on the ToolsVersion.that should be pointing to the version 12, then change it to 14, but make sure you have installed the latest version of the MSBuild from https://www.microsoft.com/en-us/download/details.aspx?id=48159 or go to C:\Program Files (x86)\MSBuild\14.0\Bin, there you should have this folder with the csc.exe compiler. If even then that doesn't resolve the issue, then try to follow this steps https://msdn.microsoft.com/en-us/library/bb383985.aspx .

在我的經驗,我在3種不同的方式解決了這個問題:

1-距離的NuGet

獲得包

2-安裝Microsoft構建TFS的服務器

3-大錘和最後的選擇上,但對我來說最好的,因爲你不需要處理上的NuGet的依賴,在TFS服務器上安裝的Visual Studio版本工具2015年,你る在這個過程中。

希望這有助於

+0

安裝這個Nuget包的依賴項修復了我的問題。如果我有100個項目,有什麼辦法可以避免安裝依賴項? – Heinrich

+0

看看我的答案在這裏http://stackoverflow.com/a/43072823/819153 – Zinov

0

我只是猜測,你必須用繩子插值代碼,並沒有proper build tools

+0

其實我有一個更高版本的服務器安裝在服務器上 – Heinrich

+0

這將有助於看到錯誤發生的代碼。 –

9

安裝MS Build tools 2015%ProgramFiles%\MSBuild\14.0\bin後,您需要override the MSBuild version for build server與新值(14.0)。

你應該閱讀MSDN文章(或this answer),但TL; DR你的選擇是:

  • 覆蓋使用/ToolsVersion開關(或/tv,對於短)當你建立了版本項目或溶液從所述命令行:

    msbuild.exe someproj.proj /tv:14.0 /p:Configuration=Debug 
    
  • 覆蓋通過設置在的ToolsVersion參數版本任務:

    <MSBuild Projects="myProject.proj" 
        ToolsVersion="14.0" 
        Targets="go" /> 
    
  • 覆蓋通過設置在一個解決方案中的項目的$(Project.ToolsVersion)財產版本。這使您可以在溶液中生成一個項目具有ToolsetVersion從使其他項目的不同:

    <Project ToolsVersion="14.0" ... </Project> 
    

The order of precedence, from highest to lowest, used to determine the ToolsVersion is:

  1. The ToolsVersion attribute on the MSBuild task used to build the project, if any.
  2. The /toolsversion (or /tv) switch that's used in the msbuild.exe command, if any.
  3. If the environment variable MSBUILDTREATALLTOOLSVERSIONSASCURRENT is set, then use the current ToolsVersion .
  4. If the environment variable MSBUILDTREATHIGHERTOOLSVERSIONASCURRENT is set and the ToolsVersion defined in the project file is greater than the current ToolsVersion , use the current ToolsVersion .
  5. If the environment variable MSBUILDLEGACYDEFAULTTOOLSVERSION is set, or if ToolsVersion is not set, then the following steps are used:
    • The ToolsVersion attribute of the Project element of the project file. If this attribute doesn’t exist, it is assumed to be the current version.
    • The default tools version in the MSBuild.exe.config file.
    • The default tools version in the registry. For more information, see Standard and Custom Toolset Configurations .
  6. If the environment variable MSBUILDLEGACYDEFAULTTOOLSVERSION is not set, then the following steps are used:
    • If the environment variable MSBUILDDEFAULTTOOLSVERSION is set to a ToolsVersion that exists, use it.
    • If DefaultOverrideToolsVersion is set in MSBuild.exe.config , use it.
    • If DefaultOverrideToolsVersion is set in the registry, use it.
    • Otherwise, use the current ToolsVersion .
+0

我嘗試了所有這些更改,即使我更改了寄存器上的值以將默認版本更改爲14.0,我也更改了MSBuild.exe.config,但一切都不成功。我的項目具有正確的ToolsVersion – Heinrich

+1

@ Heinrich您還需要確保您從「C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ BuildTools \ MSBuild \ 15.0 \ Bin \」運行msbuild.exe(不是從C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \) – Shrike

+1

對我來說,路徑是%ProgramFiles(x86)%\ Microsoft Visual Studio \ 2017 \ Community \ MSBuild \ 15.0 \ Bin \ msbuild.exe 「' – knocte

2

有你用錯了MSbuild.exe建設的機會;在Visual Studio中進行編譯(在其中工作)並檢查Output中的日誌。應該是這樣的:

1>Target "GetReferenceAssemblyPaths" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets" 

確保您使用的是MSBuild.exe在Bin目錄,在我的情況;

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSbuild.exe