zoukankan      html  css  js  c++  java
  • 在 VisualStudio 给文件起一个带分号的文件名会怎样

    小伙伴都知道在 Windows 下是支持文件名使用分号的,而写过 Roslyn 的小伙伴都知道,在 csproj 项目里面使用分号分割数组。那么在 VS 里面将一个文件名添加分号会如何?下面让咱写写看

    新建一个 WPF 项目,然后编辑文件名,添加分号

    在资源管理器的文件如下

    │  App.config
    │  App.xaml
    │  App.xaml.cs
    │  JekacareqFebarbareei.csproj
    │  MainWin;dow.xaml
    │  MainWin;dow.xaml.cs
    │
    └─Properties
            AssemblyInfo.cs
            Resources.Designer.cs
            Resources.resx
            Settings.Designer.cs
            Settings.settings
    

    可以看到 MainWindow.xaml 修改为 MainWin;dow.xaml 此时虽然在 VS 可以打开,但是使用 dotnet build 构建,会提示下面代码

    MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
    System.Reflection.TargetException: Object does not match target type.
       at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
       at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
       at Microsoft.Build.BackEnd.TaskHostTask.GetPropertyValue(TaskPropertyInfo property)
       at Microsoft.Build.Execution.TaskFactoryWrapper.GetPropertyValue(ITask task, TaskPropertyInfo property)
       at Microsoft.Build.BackEnd.TaskExecutionHost.GetItemOutputs(TaskPropertyInfo parameter)
       at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.GatherTaskOutputs(String parameterName, ElementLocation parameterLocation, Boolean outputTargetIsItem, String outputTargetName)
       at Microsoft.Build.BackEnd.TaskBuilder.GatherTaskOutputs(ITaskExecutionHost taskExecutionHost, TaskExecutionMode howToExecuteTask, ItemBucket bucket)
       at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
       at Microsoft.Build.BackEnd.TaskBuilder.InitializeAndExecuteTask(TaskLoggingContext taskLoggingContext, ItemBucket bucket, IDictionary`2 taskIdentityParameters, TaskHost taskHost, TaskExecutionMode howToExecuteTask)
       at Microsoft.Build.BackEnd.TaskBuilder.ExecuteBucket(TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Dictionary`2 lookupHash)
       at Microsoft.Build.BackEnd.TaskBuilder.ExecuteTask(TaskExecutionMode mode, Lookup lookup)
       at Microsoft.Build.BackEnd.TaskBuilder.ExecuteTask(TargetLoggingContext loggingContext, BuildRequestEntry requestEntry, ITargetBuilderCallback targetBuilderCallback, ProjectTargetInstanceChild taskInstance, TaskExecutionMode mode, Lookup inferLookup, Lookup executeLookup, CancellationToken cancellationToken)
       at Microsoft.Build.BackEnd.TargetEntry.ProcessBucket(ITaskBuilder taskBuilder, TargetLoggingContext targetLoggingContext, TaskExecutionMode mode, Lookup lookupForInference, Lookup lookupForExecution)
       at Microsoft.Build.BackEnd.TargetEntry.ExecuteTarget(ITaskBuilder taskBuilder, BuildRequestEntry requestEntry, ProjectLoggingContext projectLoggingContext, CancellationToken cancellationToken)
       at Microsoft.Build.BackEnd.TargetBuilder.ProcessTargetStack(ITaskBuilder taskBuilder)
       at Microsoft.Build.BackEnd.TargetBuilder.BuildTargets(ProjectLoggingContext loggingContext, BuildRequestEntry entry, IRequestBuilderCallback callback, String[] targetNames, Lookup baseLookup, CancellationToken cancellationToken)
       at Microsoft.Build.BackEnd.RequestBuilder.BuildProject()
       at Microsoft.Build.BackEnd.RequestBuilder.BuildAndReport()
    

    使用 msbuild 命令构建,会提示下面代码

    CoreCompile:
      C:Program Files (x86)Microsoft Visual Studio2019EnterpriseMSBuildCurrentBinRoslyncsc.exe /noconfig /nowarn:1
      701,1702 /nostdlib+ /platform:anycpu32bitpreferred /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+ /r
      eference:"C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5Microsoft.CSharp.dll" /r
      eference:"C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5mscorlib.dll" /reference
      :"C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5PresentationCore.dll" /reference
      :"C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5PresentationFramework.dll" /refe
      rence:"C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5System.Core.dll" /reference
      :"C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5System.Data.DataSetExtensions.dl
      l" /reference:"C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5System.Data.dll" /r
      eference:"C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5System.dll" /reference:"
      C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5System.Net.Http.dll" /reference:"C
      :Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5System.Xaml.dll" /reference:"C:Pro
      gram Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5System.Xml.dll" /reference:"C:Program F
      iles (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5System.Xml.Linq.dll" /reference:"C:Program Fi
      les (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5WindowsBase.dll" /debug+ /debug:full /filealign
      :512 /optimize- /out:objDebugJekacareqFebarbareei.exe /ruleset:"C:Program Files (x86)Microsoft Visual Studio2019
      EnterpriseTeam ToolsStatic Analysis Tools\Rule SetsMinimumRecommendedRules.ruleset" /subsystemversion:6.00 /targ
      et:winexe /utf8output /deterministic+ /langversion:7.3 App.xaml.cs "MainWin;dow.xaml.cs" PropertiesAssemblyInfo.cs P
      ropertiesResources.Designer.cs PropertiesSettings.Designer.cs "D:lindexiJekacareqFebarbareeiJe
      kacareqFebarbareeiobjDebugMainWin" dow.g.cs "D:lindexiJekacareqFebarbareeiJekacareqFebarbaree
      iobjDebugApp.g.cs"
      Using shared compilation with compiler from directory: C:Program Files (x86)Microsoft Visual Studio2019Enterprise
      MSBuildCurrentBinRoslyn
    CSC : error CS2001: Source file 'D:lindexiJekacareqFebarbareeiJekacareqFebarbareeidow.g.cs' could
     not be found. [D:lindexiJekacareqFebarbareeiJekacareqFebarbareeiJekacareqFebarbareei_cakuut2d_wp
    ftmp.csproj]
    CSC : error CS2001: Source file 'D:lindexiJekacareqFebarbareeiJekacareqFebarbareeiobjDebugMainW
    in' could not be found. 
    

    可以看到在 CoreCompile 这里的输出包含了 "D:lindexiJekacareqFebarbareeiJe kacareqFebarbareeiobjDebugMainWin" dow.g.cs "D:lindexiJekacareqFebarbareeiJekacareqFebarbaree iobjDebugApp.g.cs" 这就是将 MainWin;dow.xaml.cs 的输出文件 MainWin;dow.g.cs 分为两个文件,此时就发现找不到 dow.g.cs 文件

    在构建之后的 obj 文件夹里面创建了 MainWin;dow.g.cs 文件,所以文件是对的,存在坑的是 msbuild 配置的设计问题,将分号作为数组的元素分割。而文件名可以使用分号,也就是如果文件名存在分号,就将文件分割为多个文件

    看到这里小伙伴就知道了,文件名加上分号,会在构建的时候,因为设计问题,将一个文件当成两个文件,于是就找不到文件,构建不通过

    调皮的小伙伴可不要在代码文件里面添加分号

    本文代码放在 github 欢迎小伙伴访问

  • 相关阅读:
    The "tsconfig.json" file must have compilerOptions.sourceMap set to true
    *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<WKWebViewConfiguration 0x1701bcd20> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the k
    Android Service
    关于phonegap-plugin-contentsync插件
    Ionic APP 热更新 之 产品发布状态下的热更新搭建,去local-dev-addon插件
    Ionic APP 热更新
    在懒加载的Ionic工程中使用 ionic2-auto-complete 组件:Can't bind to 'dataProvider' since it isn't a known property of 'ion-auto-complete'
    Template parse errors: The pipe 'translate' could not be found
    How to update Ionic cli and libraries
    第七章 Hyper-V 2012 R2 授权管理
  • 原文地址:https://www.cnblogs.com/lindexi/p/13139057.html
Copyright © 2011-2022 走看看