Moles creation does not create all objects - moles

While trying to create a mole for some unit tests I noticed that some functions were not being 'moled'. Some functions were appearing in the xxx.moles.xml file while others were not.
To resolve this issue, I've tried reinstalling 'Pex and Moles', deleted files in the MolesAssembly folder, restarted the computer, etc.
Finally, I simply opened a console window and ran the moles.exe command from the command prompt.
"c:\program files\microsoft moles\bin\moles.exe" assembly.dll /op:"MolesAssemblies" /msbuild:"c:\windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
The first time I ran this, I received a message:
Moles : info : compilation : assembly metadata hash unchanged,
skipping code generation.
After deleting the moles in the MolesAssemblies folder, I ran the moles.exe command again and all my functions are now appearing in the xxx.moles.dll and xxx.moles.xml files.
Does anyone know why the mole generation does not work when building inside Visual Studio 2010, but it works perfectly from the command prompt?

I found the issue...I modified the .moles file before and only certain classes were added. I simply had to add more 'TypeName' and the classes/functions were included.
The reason that it 'worked' by using the moles.exe command was because I did not use the .moles file (I simply referenced the assembly). I changed the parameters for moles.exe to include the .moles file and the assembly and the results were identical to the output generated by Visual Studio. Once I notice that other parts of the code was breaking, I realized that the .moles file was incorrect.
I had something like this...
<Moles xmlns="http://schemas.microsoft.com/moles/2010/" >
<Assembly Name="Assembly.name" />
<StubGeneration>
<Types>
<Clear />
<Add FullName="Fullname_1_0" />
</Types>
</StubGeneration>
<MoleGeneration>
<Types>
<Clear />
<Add FullName ="Fullname_1_0" />
</Types>
</MoleGeneration>
</Moles>
I needed a second 'Add'
<Moles xmlns="http://schemas.microsoft.com/moles/2010/" >
<Assembly Name="Assembly.name" />
<StubGeneration>
<Types>
<Clear />
<Add FullName="Fullname_1_0" />
</Types>
</StubGeneration>
<MoleGeneration>
<Types>
<Clear />
<Add FullName ="Fullname_1_0" />
<Add TypeName="AdditionalClass"/>
</Types>
</MoleGeneration>
</Moles>

Be sure to REBUILD the test project, after modifying an assembly that is moled. Using the "clean" action on the test project will also fix this issue.

Related

nuget local feed stops working when package with two different versions is present

I am trying to use nuget local feed for publishing my packages. So, I tried to push my first component / package. I have the following nuget.config in my sdk project:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
<add key="local feed" value="x:\nuget\packages\" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
<packageManagement>
<add key="format" value="0" />
<add key="disabled" value="False" />
</packageManagement>
</configuration>
SDK Project's configuration is as follows:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Title>My custom component</Title>
<Version>0.0.1-alpha</Version>
<PackageId>$(RootNamespace)</PackageId>
</PropertyGroup>
I set the project to Release configuration, and execute Pack command. As a result, .nupkg file is created in bin/Release folder.
Inside the package manager console window, I execute the following command:
nuget add pathToNupkgFile -Source x:\nuget\packages
So far so good, package is located in folder x:\nuget\packages\companyname.components.blazor.mycomponent\0.0.1-alpha.
Now I created new solution where I want to consume package from local feed. I copied the same nuget.config file to folder where new solution was created. I open Manage Nuget Packages for Solution (short MNPfS), search for new package, and install it. All fine until this point.
Now, if I do the same procedure and create 0.0.2-alpha nupkg, after nuget add command, new version is present in x:\nuget...., but I am unable to browse local feed any more in MNPfS screen. As soon as I open MNPfS, I get following message in window where packages should be listed:
Error occured
And error list window displays following message:
Error [local feed] '.', hexadecimal value 0x00, is an invalid character. Line 1, position 1.
Now, if I delete version 0.0.1-alpha from local feed repository, then I can browse again in MNPfS and new package is displayed, and can be installed. So, the problem occurs only when two versions of same package are present.
Anyone knows why is this happening, and how can I have multiple versions of same package in local feed?
Looks like the problem was related to nuget add command -Source parameter. When source points to partition with FUSE file system, then it does not create proper nuspec file, although no error is provided in Package Manager console.
nuspec file results in content with multiple NULL values. If I specify -Source to current partition where project is, then nuspec file is properly created, and then I can just copy the content to FUSE file system, and all works OK.

Could not load file or assembly 'ClearScriptV8.win-x64.dll' or one of its dependencies. The module was expected to contain an assembly manifest

I have .NET MVC app (.NET Framework 4.6.1) and I want to add ClearScript to my app.
I've added package Microsoft.ClearScript via NuGet and after launch app I have error:
Could not load file or assembly 'file:///D:\PathToProject\bin\ClearScriptV8.win-x64.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
This file is in bin folder
What am I doing wrong? And how can I resolve this issue?
UPDATE
The next step I did removing assemblies into web.config files as #BitCortex advised:
<system.web>
<compilation>
<assemblies>
<remove assembly="ClearScriptV8.win-x64" />
<remove assembly="ClearScriptV8.win-x86" />
</assemblies>
</compilation>
</system.web>
but it didn't help.
In the result I've comment out these strings into .csproj file:
<Import Project="..\packages\Microsoft.ClearScript.V8.Native.win-x86.7.2.5\build\Microsoft.ClearScript.V8.Native.win-x86.props" Condition="Exists('..\packages\Microsoft.ClearScript.V8.Native.win-x86.7.2.5\build\Microsoft.ClearScript.V8.Native.win-x86.props')" />
<Import Project="..\packages\Microsoft.ClearScript.V8.Native.win-x64.7.2.5\build\Microsoft.ClearScript.V8.Native.win-x64.props" Condition="Exists('..\packages\Microsoft.ClearScript.V8.Native.win-x64.7.2.5\build\Microsoft.ClearScript.V8.Native.win-x64.props')" />
<Import Project="..\packages\Microsoft.ClearScript.V8.ICUData.7.2.5\build\Microsoft.ClearScript.V8.ICUData.props" Condition="Exists('..\packages\Microsoft.ClearScript.V8.ICUData.7.2.5\build\Microsoft.ClearScript.V8.ICUData.props')" />
Now the initial issue was fixed but during executing script I see the following error:
Cannot load ClearScript V8 library. Load failure information for ClearScriptV8.win-x64.dll:
C:\Users\User\AppData\Local\Temp\Temporary ASP.NET Files\vs\...\runtimes\win-x64\native\ClearScriptV8.win-x64.dll: The specified module could not be found
C:\Users\User\AppData\Local\Temp\Temporary ASP.NET Files\vs\...\ClearScriptV8.win-x64.dll: The specified module could not be found
D:\pathtoproject\ClearScriptV8.win-x64.dll: The specified module could not be found
D:\pathtoproject\bin\ClearScriptV8.win-x64.dll: The specified module could not be found
C:\WINDOWS\system32\ClearScriptV8.win-x64.dll: The specified module could not be found'
What am I doing wrong? And how can I resolve this issue?
What's assembly manifest from initial issue? Maybe some .xml file was missed into package folder or something else? (because I see in bin folder for example ClearScript.V8.dll and ClearScript.V8.xml files)
Try excluding ClearScript's native assemblies from compilation by merging the following into all of your Web.config files:
<system.web>
<compilation>
<assemblies>
<remove assembly="ClearScriptV8.win-x64" />
<remove assembly="ClearScriptV8.win-x86" />
</assemblies>
</compilation>
</system.web>

Nuget Package Manager is broken -- '' is not a valid version string in VS2019 "Manage Packages for Solution"

Package Manager in VS2019 is totally broken for me.
When I attempt to view packages for my solution the UI just says "Error occurred" with the details below, '' is not a valid version string
My build environment is heavily customized with custom targets, and packages are loaded via an out-of-VS process called "corext." So my question is what file is being parsed when attempting to load the package manager? I have a nuget.config at the root of my enlistment as well as under AppData\Roaming\NuGet which I've deleted with no results. I've tried clearing out all the nuget caches. I've tried all of the suggestions in this post without luck. If I could get any more logs at all I might be able to unblock myself. I get exactly the same results in VS 2017. Any ideas?
After countless hours of pain it was suggested to me to look for a <PackageReference> node with an unresolvable version number. To do this I went to any project in my tree and ran: msbuild /pp:pp.log foo.csproj. This generates a preprocessing log. In that log file I did a "find all instances" of "PackageReference". The first hit was a PackageReference in Directory.Build.props without a version number. The fix was to add (any) version number. I'll surely need to put in the right version number but the solution will look like this:
First, please check your nuget.config file at the root of my enlistment. Usually, when you have a new nuget.config file over the root directory path of your project.
The current project and all projects in the subdirectory will use this nuget.config rather than the global nuget.config file(AppData\Roaming\NuGet). It will add the new pakageSource and will overwrite the same name of the packagesource from the global nuget.config file.
See this document about this info.
1) Please enter the nuget.config at the root of your enlistment.
Check if you have such node like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
..............
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="test123" value="C:\xxxx\" />
<add key="github source" value="https://xxxxxxxxxxxxxxxxxxxx"/>
</packageSources>
<disabledPackageSources>
<add key="test123" value="true" />
</disabledPackageSources>
</configuration>
If so, you should check every packagesource path and make sure there is no such a space on every packagesource in case of spelling mistakes.
Or you could use disabledPackageSources node to disable any packagesources except nuget.org.
Like this:
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="test123" value="C:\xxxx\" />
<add key="github source" value="https://xxxxxxxxxxxxxxxxxxxx"/>
.........
.........
</packageSources>
<disabledPackageSources>
<add key="test123" value="true" />
<add key="github source" value="true" />
..........
</disabledPackageSources>
Then, close VS and restart your project to test again.
Or you could just delete such nuget.config to check whether there is a error node in it. Also, make a backup.
2) Second, you could run this below under Tools-->NuGet Package Manager-->Package Manager Console.
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
3) please try to a new project to check whether the issue persists in the new project. This can determine if there is a problem with nuget.config in that project.
Besides, you could try to share the nuget.config file with us.
In addition, if these do not help, please try the following steps:
a) disable any third party extensions under Extensions-->Manage Extensions
b) If these do not help, try to repair VS or update VS if there is a new update.

CruiseControl.net, send dynamic values to some files

I have been searching for a few days, I have also asked a question on the cc.net forum, but still don't have the answer.
My task is to fill Web.config with specific values during the building using cc.net. Here is the example:
I'm developing an ASP.NET website, I have a Web.config with some configuration, e.g. connection string:
<add name="ContextName" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DatabaseName;User Id = UserName;Password=UserPassword;" providerName="System.Data.SqlClient" />
After the building I want to replace some values and make the config look like this:
<add name="ContextName" connectionString="Data Source=%SERVER%;Initial Catalog=%DATABASE%;User Id = %USER%;Password=%PASSWORD%;" providerName="System.Data.SqlClient" />
I tried this solution, but it didn't help me (or maybe I didn't understand how to use it properly).
Please help me to solve the task.
Thanks!
You can try to use this Config Transformation Tool which is XDT transformation command tool based on XDT (web.config) transform engine, which allows you to run XDT transformation on any XML files. You can use ccnet's task block to run it after your msbuild
<tasks>
<exec>
</exec>
</tasks>
More on ccnet executable task see here.
For more information on XDT transformation see this link in MSDN library
You can create a target on your build file to update the web.config and call that target after the build. I use something similar in my build files, here is an example:
<target name="update-config" >
<property name="export.config" value="" unless="${property::exists('export.config')}" />
<call target="${config-settings}" /> <!-- test or stage -->
<xmlpoke file="${export.config}" xpath="/configuration/appSettings/add[#key='ContextName']/#connectionString" value="${configValue.connectionString}" failonerror="true" />
</target>
<target name="test">
<property name="configValue.connectionString" value="test connection string here" />
</target>
<target name="stage">
<property name="configValue.connectionString" value="stage connection string here" />
</target>
After executing the target that compile your code and export you can run the target update-config, in this case I'm expecting a variable export.config with the path of the exported web.config then calling another target that sets the the value of the connectionstring variable (this can be target test or stage) and finally xmlpoke the web.config with the value.
Hope this helps!

How to deploy different App.config values (with WiX)

I've been looking for a best practice recommendation on how to deploy an application with a WiX installer for different values in its App.config file. For example.
On my local development machine, I use App.config settings for our test environment:
<configuration>
<appSettings>
<WorkingDirectory>C:\Working</WorkingDirectory>
</appSettings>
<connectionStrings>
<add name="ApplicationEntities"
connectionString="[TestingConnectionString]"
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
When I deploy to a test environment, those settings are acceptable. However, when we deploy to a production environment, I'd like them to be different. For example:
<configuration>
<appSettings>
<WorkingDirectory>\\prodserver\Working</WorkingDirectory>
</appSettings>
<connectionStrings>
<add name="ApplicationEntities"
connectionString="[ProductionConnectionString]"
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
The answer to my question may very well be independent of WiX. But just in case, here is my WiX Product.wxs file's relavent fragment:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ProductComponent" Guid="{MY-GUID}">
<File Id="Application.exe"
Name="Application.exe"
Source="..\Application.exe"
Vital="yes"
KeyPath="yes"
DiskId="1" />
<File Id="Application.exe.config"
Name="Application.exe.config"
Source="..\Application.exe.config"
Vital="yes"
KeyPath="no"
DiskId="1" />
</Component>
</ComponentGroup>
</Fragment>
This setup ends with a manual edit of the App.config on the production server, which invites manual error. What would be a better way to handle this to accommodate an automated deployment?
I can think of two options, either deploy the app.config file and edit it using the XmlFile Element, or maintain multiple app.config files each representing your target environment, then deploy the appropriate file.
Here's an exmaple of both options, notice that I copy the file rather than just placing it on the file system. This serves two purposes, firstly you can see by the filename which one has been deployed, secondly if development.app.config and production.app.config are placed in the same location you will get an ICE30 validation error, by copying the file afterwards it avoids this error.
Notice also that I have a condition associated with the component, you'll need to decide how you identify which environment you are deploying to. Some ideas could be to use the machine name, the OU or simply pass it in on the command line as a property.
<Component Id="development.app.config" Guid="*">
<Condition>DEVELOPMENT</Condition>
<File Name="development.app.config" KeyPath="yes">
<CopyFile Id="development.app.config" DestinationName="app.config" />
</File>
<util:XmlFile
Id="WorkingDirectory"
Action="setValue"
File="app.config"
ElementPath="/configuration/appSettings"
Name="WorkingDirectory"
Value="C:\Working"
Permanent="no" />
</Component>
<Component Id="production.app.config" Guid="*">
<Condition>PRODUCTION</Condition>
<File Name="production.app.config" KeyPath="yes">
<CopyFile Id="production.app.config" DestinationName="app.config" />
</File>
<util:XmlFile
Id="WorkingDirectory"
Action="setValue"
File="app.config"
ElementPath="/configuration/appSettings"
Name="WorkingDirectory"
Value="\\prodserver\Working"
Permanent="no" />
</Component>