简体   繁体   中英

C# String-Interpolation in InfoPath Form

I am trying to add some code to an InfoPath 2013 form for use on a SharePoint 2013 website.

This appears to be working normally after installing Visual Studio 2012 and opening it via InfoPath .

However, after importing some of my old code (which makes use of the string-interpolation introduced in C# 6.0 ), I now see this error:

Unexpected character '$'

On lines where interpolation is used.

I tried running Install-Package Microsoft.Net.Compilers -Version 1.3.2 , but NuGet complains that:

The element 'metadata' in namespace ' http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd ' has invalid child element 'developmentDependency' in namespace ' http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd '.

List of possible elements expected: 'iconUrl, summary, title, projectUrl, references, frameworkAssemblies, copyright, releaseNotes, licenseUrl, tags, dependencies, language, description' in namespace ' http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd '.

So I tried update NuGet as per this answer , but then I see:

The term 'nuget' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

What is going on here? Am I wasting my time trying to use C# 6.0 with InfoPath , or is there something wrong with my configuration?

Please note that InfoPath 2013 will only allow custom code if using Visual Studio 2012 . Other wise I would be using 2015 .

I was able to resolve this by following these steps:

First, update NuGet using the following method:

  1. From the Tools menu select Extensions and Updates.
  2. Then in the dialog that opens select the Updates tab.
  3. Then select Visual Studio Gallery.
  4. Select NuGet Package Manager for Visual Studio and click the Update button.

Next, exit Visual Studio 2012 and InfoPath 2013 (note that exiting only VS will not work, as InfoPath appears to keep it open in the background for quick access).

Now, Start both up again and try again. This time, I was able to run Install-Package Microsoft.Net.Compilers in the Package Manager Console and C# 6.0 appears to have been installed.

VS2012 sill processes the new string-interpolation as an error, so these do appear in the error window and I can see squiggly red underlining in the text editor.

I have opted to forgo the new string-interpolation as dealing with these fake errors is too annoying. I did this by unloading my .csproj file and removing the reference to Microsoft.Net.Compilers .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM